Repository navigation
diffview: diff a large file three times faster - #12
Merged
Merged
Conversation
A diff of a file of 100,000 lines took 66 ms before it drew a line. Most
of the time went to the regular expression that scopesOf ran on each
line to find the declarations, and to go-udiff's splitLines, which
decodes every rune to find the line ends.
isDeclaration now reads the words at the start of a line by hand, and
matches the same lines as the regular expression, which a test keeps as
the reference. The cheap check for a word at column 0 comes first, so
most top-level lines skip it.
Edits replaces udiff.Lines, in the way of @pierre/patches: it finds the
line ends with strings.IndexByte, diffs integer ids of the lines, and
slices the new text instead of copying it. It returns the same edits as
udiff.Lines.
BenchmarkDiffHunks, 100,000 lines, Apple M4:
one line changed in 2,000: 65.9 ms, 40.9 MB -> 21.3 ms, 24.2 MB
2,000 lines inserted: 40.2 ms, 41.6 MB -> 15.3 ms, 24.8 MB
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.
A diff of a file of 100,000 lines took 66 ms before it drew a line. Most of the time went to the regular expression that
scopesOfran on each line, and to go-udiff'ssplitLines, which decodes every rune to find the line ends.isDeclarationreads the words at the start of a line by hand instead of the regular expression. The cheap check for a word at column 0 now comes first.Editsreplacesudiff.Lines, in the way of @pierre/patches: it finds line ends withstrings.IndexByte, diffs integer ids of the lines, and slices the new text instead of copying it. No new dependency.Both give the same output as before.
TestIsDeclarationMatchesRegexpchecks 200,000 random lines against the old regular expression, andTestEditsMatchUdiffchecks 10,000 random pairs of texts againstudiff.Lines.BenchmarkDiffHunks, 100,000 lines, Apple M4, mean of 10 runs:The largest cost left is the
splitLinesinsideudiff.ToUnifiedDiff, about a third of the time. Removing it needs our own hunk builder, so it is not in this PR.