fix: reduce retained geometry memory in large reviews#521
Open
matthew-hre wants to merge 2 commits into
Open
Conversation
Contributor
|
PR author is not in the allowed authors list. |
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.
Hello! Been a big fan of Hunk recently, I use it basically every day at work -- however, it's been a bit of a memory-hog on my machine, so I thought I'd start doing some digging and hopefully contribute some performance patches! First contribution on this project, let me know if I missed anything.
This PR introduces a fix that reduces memory usage in large reviews by making diff section geometry hold on to less data.
Previously,
DiffSectionGeometrywas holding on to the full planned row stream for every measured file section -- most review interactions really only need lightweight geometry data: row bounds, hunk bounds, body height, and lookup maps.Since we already window the rendered rows, keeping full planned rows for the entire changeset means we're still retaining a bunch of row objects, even when most files weren't mounted.
This changes geometry to keep the bounds/navigation data eagerly, but rebuild planned rows lazily, only when copy selection asks for row content.
I also added a focused
bench:geometry-memorybenchmark so this path is easier to measure next time.Results
The biggest improvement showed up on the huge synthetic review benchmark:
The resize memory benchmark also improved, which makes sense:
Little less impressive on the
memory.tsbenchmark, but still positive:I also ran the new focused geometry benchmark on this branch:
This should be fairly cut-and-dry. Rendering still builds planned rows for mounted sections, and copy selection still gets planned rows when it needs them. The only difference really is that cached geometry no longer keeps those rows alive for every file by default.