Skip to content

Commit 9e6f195

Browse files
authored
ref(glob): Switch glob implementations to regex-lite (#3926)
Switches the regex implementation for globs from `regex` to regex-lite`, this should bring down memory consumption for all globs. This is just a temporary stop-gap to unblock the project cache improvements started in #3892, eventually the glob implementations should be unified and ideally be as much as possible regex free.
1 parent 48878ef commit 9e6f195

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Make the tcp listen backlog configurable and raise the default to 1024. ([#3899](https://github.com/getsentry/relay/pull/3899))
2020
- Extract `user.geo.country_code` into span indexed. ([#3911](https://github.com/getsentry/relay/pull/3911))
2121
- Add `span.system` tag to span metrics ([#3913](https://github.com/getsentry/relay/pull/3913))
22+
- Switch glob implementations from `regex` to `regex-lite`. ([#3926](https://github.com/getsentry/relay/pull/3926))
2223
- Extract client sdk from transaction into profiles. ([#3915](https://github.com/getsentry/relay/pull/3915))
2324
- Extract `user.geo.subregion` into span metrics/indexed. ([#3914](https://github.com/getsentry/relay/pull/3914))
2425

Cargo.lock

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ rdkafka-sys = "4.3.0"
136136
# Git revision until https://github.com/redis-rs/redis-rs/pull/1097 (merged) and https://github.com/redis-rs/redis-rs/pull/1253 are released.
137137
redis = { git = "https://github.com/getsentry/redis-rs.git", rev = "939e5df6f9cc976b0a53987f6eb3f76b2c398bd6", default-features = false }
138138
regex = "1.10.2"
139+
regex-lite = "0.1.6"
139140
reqwest = "0.11.1"
140141
rmp-serde = "1.1.1"
141142
rust-embed = "8.0.0"

relay-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ workspace = true
1616
chrono = { workspace = true }
1717
globset = { workspace = true }
1818
once_cell = { workspace = true }
19-
regex = { workspace = true }
19+
regex-lite = { workspace = true }
2020
sentry-types = { workspace = true }
2121
serde = { workspace = true }
2222

relay-common/src/glob2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::sync::OnceLock;
44
use std::{fmt, str};
55

6-
use regex::Regex;
6+
use regex_lite::Regex;
77

88
/// Glob options represent the underlying regex emulating the globs.
99
#[derive(Debug)]
@@ -70,7 +70,7 @@ impl<'g> GlobBuilder<'g> {
7070
let regex = GLOB_RE.get_or_init(|| Regex::new(r"\\\?|\\\*\\\*|\\\*|\?|\*\*|\*").unwrap());
7171

7272
for m in regex.find_iter(self.value) {
73-
pattern.push_str(&regex::escape(&self.value[last..m.start()]));
73+
pattern.push_str(&regex_lite::escape(&self.value[last..m.start()]));
7474
match m.as_str() {
7575
"?" => pattern.push_str(self.groups.question_mark),
7676
"**" => pattern.push_str(self.groups.double_star),
@@ -79,7 +79,7 @@ impl<'g> GlobBuilder<'g> {
7979
}
8080
last = m.end();
8181
}
82-
pattern.push_str(&regex::escape(&self.value[last..]));
82+
pattern.push_str(&regex_lite::escape(&self.value[last..]));
8383
pattern.push('$');
8484

8585
Glob {

relay-common/src/glob3.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use std::fmt;
44
use std::sync::OnceLock;
55

66
use globset::GlobBuilder;
7-
use regex::bytes::{Regex, RegexBuilder};
7+
use regex_lite::{Regex, RegexBuilder};
88
use serde::{Deserialize, Deserializer, Serialize, Serializer};
99

1010
/// Returns `true` if any of the patterns match the given message.
11-
fn is_match(globs: &[Regex], message: &[u8]) -> bool {
12-
globs.iter().any(|regex| regex.is_match(message.as_ref()))
11+
fn is_match(globs: &[Regex], message: &str) -> bool {
12+
globs.iter().any(|regex| regex.is_match(message))
1313
}
1414

1515
/// A list of patterns for glob matching.
@@ -38,7 +38,7 @@ impl GlobPatterns {
3838
/// Returns `true` if any of the patterns match the given message.
3939
pub fn is_match<S>(&self, message: S) -> bool
4040
where
41-
S: AsRef<[u8]>,
41+
S: AsRef<str>,
4242
{
4343
let message = message.as_ref();
4444
if message.is_empty() {

0 commit comments

Comments
 (0)