feat: improve prefilter#38
Merged
Merged
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request introduces comprehensive regex pattern analysis to improve prefiltering performance in the regex-core crate. The changes extract deterministic "must-have" literals, candidate literals (needles), and nullability from regex ASTs, enabling more efficient matching through multi-level prefiltering before full VM evaluation.
Changes:
- Added AST analysis infrastructure (
AstAnalysisstruct andanalyze_astfunction) to extract must_literals, needles, and nullability from regex patterns - Updated the
RegexAPI to leverage analysis results with a multi-level prefiltering strategy (nullable check → must_literals check → needle-based position hints → full VM scan) - Modified evaluator to support matching from multiple candidate start positions via
eval_from_starts
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/regex-core/src/engine/ast.rs |
Implements AST analysis with functions to extract must_literals, needles, and nullable flags; includes comprehensive tests |
crates/regex-core/src/lib.rs |
Integrates analysis results into Regex struct; implements multi-level prefiltering strategy in is_match_line |
crates/regex-core/src/engine.rs |
Adds compile_pattern_with_analysis and compile_pattern_with_must_literals functions; updates match_line_from_start to match_line_from_starts |
crates/regex-core/src/engine/evaluator.rs |
Changes eval_from_start to eval_from_starts to support multiple start positions |
.github/instructions/review/pr-review.instructions.md |
Adds code review checklist guidelines for Copilot reviewers (requests Japanese responses) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a comprehensive regex pattern analysis to the
regex-corecrate, enabling extraction of deterministic "must-have" substrings, candidate literals (needles), and nullability from regex ASTs. The engine and evaluator APIs are updated to leverage these analyses, improving pre-filtering and match logic. Extensive tests are added to verify correctness and edge cases.Regex pattern analysis and integration:
AstAnalysisstruct and theanalyze_astfunction toengine/ast.rs, which extract must-have substrings, candidate literals, and nullability from regex ASTs. Limits are enforced to prefer longer literals and lexicographic order.Regexstruct inlib.rsto storemust_literals,needles, andnullable, and to initialize these viacompile_pattern_with_analysis, replacing the previousfirst_stringslogic. [1] [2]compile_pattern_with_analysisandcompile_pattern_with_must_literals, which return compiled instructions along with analysis results.Evaluator and matching improvements:
eval_from_starttoeval_from_startsinevaluator.rs, allowing matching from multiple provided start indices, and updated engine and tests accordingly. [1] [2]engine.rsandevaluator.rsto verify new analysis features, must literals extraction, needle extraction, nullability, and multi-start matching. [1] [2] [3]Documentation and review instructions:
.github/instructions/review/pr-review.instructions.md, emphasizing code quality, naming, error handling, test coverage, and performance.