perf: replace difflib fuzzy aligner with O(n*m^2) LCS DP#442
Merged
Conversation
9636003 to
3691bf3
Compare
c9dc107 to
ec99d10
Compare
ec99d10 to
9d8cfb6
Compare
9d8cfb6 to
d8c8e95
Compare
25d0cc4 to
ee3d65d
Compare
Replace the legacy fuzzy aligner with an O(n*m^2) time, O(m^2) memory LCS DP gated by coverage and density rules, where n is source length and m is extraction length (typically 3-8 tokens). The old path enumerated candidate windows and scored each with difflib, which scales badly on long documents. Speedup: 1,000-token sources drop from ~33s to under 5ms; 5,000-token sources from ~69min (est.) to under 20ms. Addresses #386. Related: #188.
ee3d65d to
fc06ba8
Compare
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.
Fixes #386, fixes #197. Related: #188.
Summary
Replace the legacy fuzzy aligner with an O(n·m²) time, O(m²) memory
LCS DP gated by coverage and density rules, where n is source length
and m is extraction length (typically 3-8 tokens). The old path
enumerated candidate windows and scored each with difflib, which
scales badly on long documents.
Speedup: 1,000-token sources drop from ~33s to under 5ms; 5,000-token
sources from ~69min (est.) to under 20ms.
Changes
no allocation guard needed
sub-match can be considered when the max-match span fails density
enable_fuzzy_alignment so exact-match-only callers stay quiet
Test plan
regression, positional API compat, deprecation warning, param
validation, fuzzy-disabled quiet path, and end-to-end extract()
integration