Skip to content

Add heuristic option with git-style cost cap - #12

Merged
krkarma777 merged 1 commit into
masterfrom
feature/heuristic-option
Aug 31, 2026
Merged

Add heuristic option with git-style cost cap#12
krkarma777 merged 1 commit into
masterfrom
feature/heuristic-option

Conversation

@krkarma777

Copy link
Copy Markdown
Owner

Summary

  • New DiffOptions.heuristic (default false = exact): caps each subproblem's middle-snake search at max(64, sqrt(N+M)) phases; past the cap it splits at the furthest-reaching point of either direction (the git xdiff strategy)
  • Measured on the 8 KB completely-different char worst case: 217 ms → 8.0 ms (27×) with an edit script only +8.1% above minimal — versus diff-match-patch's own heuristic mode at ~657 ms on the same input
  • While the true edit distance is under the cap, output is byte-identical to exact mode (tested); round-trip validity always holds
  • diffTokens gains an optional options argument carrying the flag; refine sub-diffs inherit it

Test Plan

  • 5 new tests: exact-equivalence under the cap (600 pairs), round-trip fuzz on wildly different inputs (450 diffs), edit-count sanity vs exact, refine interplay, trivial cases
  • Full suite 39/39, typecheck clean, build OK

@krkarma777
krkarma777 merged commit afdd5c3 into master Aug 31, 2026
5 checks passed
@krkarma777
krkarma777 deleted the feature/heuristic-option branch August 31, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant