feat: improve prefilter#39
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances the regex engine's prefilter optimization by introducing AST-based analysis to extract must-have literals, candidate needles, and nullable information. The improvements enable early rejection of non-matching inputs and optimized search starting positions.
Changes:
- Added comprehensive AST analysis infrastructure to extract must literals (guaranteed to appear in matches), needles (candidate search positions), and nullable status
- Refactored regex matching to use a multi-stage prefilter: nullable fast-path, must-literal filtering, needle-based position hinting, and full evaluation fallback
- Updated the evaluator to support matching from multiple candidate starting positions instead of just one
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/regex-core/src/engine/ast.rs | Implements AST analysis logic for extracting must literals, needles, and nullable information with comprehensive test coverage |
| crates/regex-core/src/lib.rs | Integrates prefilter optimizations into the Regex struct with nullable/must/needle checks and byte-to-char position conversion |
| crates/regex-core/src/engine/evaluator.rs | Extends evaluator to match from multiple starting positions (renamed eval_from_start to eval_from_starts) |
| crates/regex-core/src/engine.rs | Adds compile_pattern_with_analysis to return both compiled instructions and analysis results |
| .github/instructions/review/pr-review.instructions.md | Adds Copilot review instructions (unrelated to prefilter functionality) |
|
|
||
| You are a senior code reviewer ensuring high standards of code quality | ||
|
|
||
| When performing a code review, **respond in Japanese**. |
There was a problem hiding this comment.
The instruction to "respond in Japanese" seems unusual for a codebase that uses English throughout. This should be removed unless there's a specific reason for requiring Japanese responses in code reviews.
| # GitHub Copilot Instructions | ||
|
|
||
| You are a senior code reviewer ensuring high standards of code quality | ||
|
|
||
| When performing a code review, **respond in Japanese**. | ||
| Please focus on the following checklist: | ||
|
|
||
| ## Checklist | ||
|
|
||
| - Code is simple and readable | ||
| - Functions and variables are well-named | ||
| - No duplicated code | ||
| - Proper error handling | ||
| - No exposed secrets or API keys | ||
| - Input validation implemented | ||
| - Good test coverage | ||
| - Performance considerations addressed | ||
| - Time complexity of algorithms analyzed | ||
| - Integrated libraries have compatible licenses (no license conflicts in dependencies) | ||
| - No overly large functions (>50 lines) | ||
| - No overly large files (>800 lines) | ||
| - No deeply nested logic (>4 levels) | ||
| - No hardcoded configuration values; configuration is externalized | ||
| - No unexplained magic numbers; constants are named and documented |
There was a problem hiding this comment.
This entire file appears to be unrelated to the PR's stated purpose of improving prefilter functionality. The PR description mentions analyzing AST for must literals, nullable, and needles, but doesn't mention adding Copilot review instructions. Consider removing this file from this PR or explaining its relevance in the PR description.
Analyze ast and see the following