Repository navigation
Improve performance with very long diffs - #6121
Merged
Merged
Conversation
With no diff renderer configured, opening the jump-to-file menu for the diff of a commit that adds or deletes a file of 100,000 lines takes more than 20 seconds, and so does picking a file from it. In such a diff, moving the selection by change block takes as long for each key press. All this time the UI is frozen. To find out which line of which file each row of the main view shows, lazygit parses the view's content as a diff. For every line of a file's diff it asks the parsed patch for the line's number in the new and in the old file, and each of these calls counts the lines of the hunk before it. So parsing takes time quadratic in the length of a hunk, and the diff of a new or deleted file is a single hunk. For a diff of 200,000 lines, one parse took about 10 seconds, and opening the menu parses it twice. A diff renderer that states which line each row shows, such as delta, doesn't go through this parse. Number all lines of the patch in one pass instead. Parsing that diff now takes about 40 milliseconds. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Several actions on the selected lines of a diff look up those lines in the diff of their file by their line numbers: staging, unstaging and discarding them, editing the hunk they are in, and adding them to a custom patch. Showing which lines of a diff are in the custom patch does the same lookup the other way round. For this, the change lines of the file's diff are indexed by their line numbers. The index asked the patch for the number of each change line separately, and each of these calls counts the lines of the hunk before the line. So for a new file of 100,000 lines, building the index took 2 seconds. Number all lines of the patch in one pass instead. Building the index for that file now takes 4 milliseconds. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Every query about the lines of the main view, such as moving the selection to the next change block, finds out which line of which file each row shows. For every row, this joined the path that the diff states with the path of the worktree. In a diff of 300,000 lines, this took more than half of the time of the query. The lines of a diff come file by file, so remember the last path that was made absolute and reuse it while the path stays the same. Do the same in the other places that go through every line of a diff. A query over that diff now takes about 27 milliseconds instead of 63. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Under a diff renderer that states which diff line each row shows, such as delta, moving the selection by change block in a diff of 300,000 lines lags noticeably. One reason is that the queries about the lines of the main view collect the records of every row from the row's cells, going through every cell of every row. Under delta, a row has about 130 cells. Collect the records of a line once, when the write cursor moves on to the next line, and take them from there. A line that is written to again is read from its cells until it has been finished again. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Under a diff renderer that states which diff line each row shows, such as delta, the queries about the lines of the main view read the rows by those records alone. Still, they took the text of every row as well, and for a diff of 300,000 lines this was most of the time each of them took. Moving the selection by change block runs two of them for every key press. Take the records of the rows first, and their text only if no row states a diff line. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 task
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.
Parsing long diffs was very slow, especially for commits that add or remove files with hundreds of thousands of lines. This caused very noticeable lags for certain operations such as scrolling down in such a diff using
>, or bringing up the<ctrl-g>files menu.