Conversation
|
GNU grep testsuite comparison: |
Merging this PR will regress 1 benchmark
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
d499dbf to
d729ce2
Compare
| if options.contains(RegexOptions::REGEX_OPTION_IGNORECASE) { | ||
| case_fold_flag &= !onig_sys::INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR; | ||
| /// Convert POSIX Basic Regular Expression (BRE) to standard regex syntax for fancy-regex. | ||
| fn transpile_bre(pattern: &str) -> UResult<String> { |
There was a problem hiding this comment.
Did you implement it at uutils/expr and copy-pasted to grep and findutils? If so, we should move it to uucore.
lhecker
left a comment
There was a problem hiding this comment.
I have seen this code before as it is almost line for line identical to the code that Claude spat out when this was being prototyped earlier this year. Passing the standard of the current test suites does not mean it's good code.
A great example for that is the O(n) single codepoint parser, where n = line length. Did the test suite catch that -w expressions are now O(n^2)? No. Neither did it catch the leftmost longest rule being broken.
I'll be closing this PR because I'm fairly confident that you cannot fix the leftmost longest issue in a reasonable way. See rust-lang/regex#1126.
| let next_char = match std::str::from_utf8(&line[end..]) { | ||
| Ok(s) => s.chars().next(), | ||
| Err(e) if e.valid_up_to() > 0 => { | ||
| std::str::from_utf8(&line[end..end + e.valid_up_to()]) | ||
| .ok() | ||
| .and_then(|s| s.chars().next()) | ||
| } | ||
| Err(_) => None, | ||
| }; |
There was a problem hiding this comment.
An unbounded O(n) algo to get the next codepoint? That can be done better, I'm sure.
| } | ||
|
|
||
| /// Word-boundary check `-w`. | ||
| /// NOTE that `-w` does not check both sides, unlike `\b` in a regex. |
There was a problem hiding this comment.
You should reinstate this comment. It's still true.
| /// Sort alternation branches by descending length so that leftmost-first engines | ||
| /// match the longest alternative first (POSIX leftmost-longest semantics). |
There was a problem hiding this comment.
How would you even know what the longest branch is? In aaaaa|a* the 2nd branch is shorter and yet longer.
Proof:
printf 'aaaaaa' | cargo run -- -E -o 'aaaaa|a*'This issue is as far as I'm aware unfixable and so this PR can be closed. See rust-lang/regex#1126.
There was a problem hiding this comment.
this is fixable in fancy-regex because it is a backtracking engine, I prepared a PR to enable it: fancy-regex/fancy-regex#281
| if options.contains(RegexOptions::REGEX_OPTION_IGNORECASE) { | ||
| case_fold_flag &= !onig_sys::INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR; | ||
| /// Convert POSIX Basic Regular Expression (BRE) to standard regex syntax for fancy-regex. | ||
| fn transpile_bre(pattern: &str) -> UResult<String> { |
There was a problem hiding this comment.
This and the one below are a very hard read.
|
I’m really sorry about the issues here, and thanks for taking the time to review this and point them out. I’ll close this PR. |
|
You don't have to be sorry! I do appreciate when people take their time to contribute improvements. My primary feedback is to give your code a closer read before submitting it as AIs are smart but very overconfident. |
|
@wtcpython You can reopen this PR and put it into "draft" if you'd like. Once the fancy-regex PR has been merged and released we can revisit this PR. |
|
I did some benchmarks with the just released fancy-regex 0.19.2 and my I found that this PR unfortunately regresses performance by ~8x in my tests. It's worth noting that onig too is already ~10x slower than GNU grep. However, fancy-regex would make that two orders of magnitude, which (at least in my use cases) makes it perceptible. I toyed around with it for a bit and found that that about half of that is due to |
it does indeed, although in this case EDIT: I forgot to mention, with leftmost-longest mode, a lot more work has to be done in the fancy-regex VM, it can't simply delegate to regex-automata. Seek mode should improve things a lot though. |
|
|
|
I tried enabling Benchmarked on a 641 MB / 10,000,000-line log:
|
|
That is really nice! But you may have to repeat the GNU grep benchmark. 3ms would mean it ran at 213GB/s which is unrealistic. |
Closes #60
Closes #20