-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: performance, adding pcre2 backend + regex-shards (5-15% speedup) #1968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8e38d9b
b2f6492
421b1f4
9bc9762
c6454bc
14204e6
ebc3c0a
cf238bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [env] | ||
| # Only takes effect when the optional `pcre2` feature is enabled and `pcre2-sys` | ||
| # is built. Keeps runtime free of dynamic libpcre2 dependency. | ||
| PCRE2_SYS_STATIC = { value = "1", force = false } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,11 +75,13 @@ getrandom = { version = "0.3" } | |
| esaxx-rs = { version = "0.1.10", default-features = false, features=[]} | ||
| monostate = "0.1.12" | ||
| ahash = { version = "0.8.11", features = ["serde"] } | ||
| pcre2 = { version = "0.2", optional = true } | ||
| dary_heap = { version = "0.3.6", features = ["serde"] } | ||
| compact_str = { version = "0.9", features = ["serde"] } | ||
|
|
||
| [features] | ||
| default = ["progressbar", "onig", "esaxx_fast"] | ||
| pcre2 = ["dep:pcre2", "fancy-regex"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is one declared with the |
||
| esaxx_fast = ["esaxx-rs/cpp"] | ||
| progressbar = ["indicatif"] | ||
| http = ["hf-hub"] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,30 @@ impl SysRegex { | |
| regex: Regex::new(regex_str)?, | ||
| }) | ||
| } | ||
|
|
||
| pub fn find_matches( | ||
| &self, | ||
| inside: &str, | ||
| ) -> Result<Vec<(Offsets, bool)>, Box<dyn Error + Send + Sync + 'static>> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't need to be a |
||
| if inside.is_empty() { | ||
| return Ok(vec![((0, 0), false)]); | ||
| } | ||
|
|
||
| let mut prev = 0; | ||
| let mut splits = Vec::with_capacity(inside.len()); | ||
| for matched in self.regex.find_iter(inside) { | ||
| let matched = matched?; | ||
| if prev != matched.start() { | ||
| splits.push(((prev, matched.start()), false)); | ||
| } | ||
| splits.push(((matched.start(), matched.end()), true)); | ||
| prev = matched.end(); | ||
| } | ||
| if prev != inside.len() { | ||
| splits.push(((prev, inside.len()), false)); | ||
| } | ||
| Ok(splits) | ||
| } | ||
| } | ||
|
|
||
| pub struct Matches<'r, 't>(fancy_regex::Matches<'r, 't>); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,26 @@ impl SysRegex { | |
| regex: Regex::new(regex_str)?, | ||
| }) | ||
| } | ||
|
|
||
| pub fn find_matches(&self, inside: &str) -> Result<Vec<(Offsets, bool)>> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here for the |
||
| if inside.is_empty() { | ||
| return Ok(vec![((0, 0), false)]); | ||
| } | ||
|
|
||
| let mut prev = 0; | ||
| let mut splits = Vec::with_capacity(inside.len()); | ||
| for (start, end) in self.regex.find_iter(inside) { | ||
| if prev != start { | ||
| splits.push(((prev, start), false)); | ||
| } | ||
| splits.push(((start, end), true)); | ||
| prev = end; | ||
| } | ||
| if prev != inside.len() { | ||
| splits.push(((prev, inside.len()), false)); | ||
| } | ||
| Ok(splits) | ||
| } | ||
| } | ||
|
|
||
| impl Pattern for &Regex { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which is always?