Repository navigation
Make the half-match search honor DiffTimeout - #163
Draft
flostadler wants to merge 1 commit into
Draft
flostadler wants to merge 1 commit into
flostadler wants to merge 1 commit into
Conversation
diffHalfMatchI did not check the deadline, and its seed search and loop are quadratic on repetitive text. Pass the deadline into the half-match search, check it during the seed search, and return no half-match when it has passed, so DiffMain falls back to bisect. Fixes sergi#162 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
flostadler
marked this pull request as draft
October 13, 2026 14:07
Owner
|
Thanks for this. I tested it on top of current master and it fixes #162: the repro now stops at the timeout (about 200ms instead of 5.7s), and the full suite passes with |
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 #162
Problem
When
DiffTimeoutis more than zero,DiffMaincan use much more time thanDiffTimeout.diffHalfMatchIdoes not examine the deadline. On repetitive text, its loop and its seed search (runesIndexOf, a simple search) take quadratic time.Change
diffComputegives its deadline todiffHalfMatchanddiffHalfMatchI.runesIndexOfDeadline, does the seed search. It examines the deadline at the first position and after each 1024 positions. If the deadline is past, it returns -1.diffHalfMatchIexamines the deadline. If the deadline is past, it returns no half-match. ThendiffComputeusesdiffBisect, which also stops at the deadline.DiffHalfMatchuses a zero deadline, thus its results do not change.runesIndexandrunesIndexOfdo not change.Results
DiffTimeout = 100ms. macOS arm64."b" + "a"×100,000 + "c"vs"d" + "a"×100,000 + "e"Tests
TestDiffMainHalfMatchHonorsDeadlinedoes the two cases above. It makes sure thatDiffMainstops in less than 2 s and that the diff gives the two original texts again. Without the change, the test fails.go test ./...,go test -race ./diffmatchpatch/,go vet ./...andgofmtpass.🤖 Generated with Claude Code