perf: DFA FindAll early termination + prefilter skip#129
Merged
Conversation
…inputs findIndicesDFAAt used DFA.FindAt (longest-match O(n) scan) as prefilter, then PikeVM re-scanned for exact bounds. For FindAll on dense-match inputs (e.g., template patterns with 2000 matches over 50KB), total DFA work was ~50MB due to O(n^2) scanning. Fix: - Added DFA.IsMatchAt() with early termination — O(k) where k is distance to first match, vs O(n) for longest-match scan - Prefilter skip: when prefix prefilter available, jump PikeVM directly to candidate position instead of scanning from 'at' Template pattern FindAll improved ~37% (5.4ms -> 3.4ms). Remaining 2.8x gap vs stdlib is PikeVM per-byte cost (UTF-8 dot handling).
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Benchmark ComparisonComparing Summary:
|
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.
Summary
findIndicesDFAAtas prefilter check, eliminating O(n²) total scanning in FindAll on dense-match inputs.{{), jump PikeVM directly to the candidate position instead of scanning fromat. Avoids PikeVM processing non-matching regions.\{\{(.*?)\}\}FindAll improved ~37% (5.4ms → 3.4ms on 50KB with 2000 matches)..handling) — separate optimization task.Follow-up to #128 (BoundedBacktracker span fix). Both reported by @kostya via #124.
Test plan
go test ./...— all 9 packages passgofmt -l .— no formatting issues