jesseduffield / lazygit

simple terminal UI for git commands
MIT License
47.94k stars 1.72k forks source link

Reduce memory consumption when loading large number of commits #3687

Closed stefanhaller closed 1 week ago

stefanhaller commented 1 week ago

(Github decided to auto-close #2533, and I don't see any way to reopen it, so opening a new one here. Please see there for discussion and review.)

When pressing > in the commits panel to trigger loading all the remaining commits past the initial 300, memory consumption is a pretty big problem for larger repositories.

The two main causes seem to be

  1. the cell memory from rendering the entire list of commits into the gocui view
  2. the pipe sets when git.log.showGraph is on

This PR addresses only the first of these problems, by not rendering the entire view, but only the visible portion of it. Since we already re-render the visible portion of the view on every layout call, this was relatively easy to do.

Below are some measurements for our repository at work (261.985 commits):

master this PR
without Graph 855 MB 360 MB
with Graph 3.1 GB 770 MB

And for the linux kernel repo (1.170.387 commits):

master this PR
without Graph 5.8 GB 1.2G
with Graph Killed by the OS after it reached 86.9 GB 39.9 GB

The measurements were taken after scrolling all the way down in the list of commits. They have to be taken with a grain of salt, as memory consumption fluctuates quite a bit in ways that I find hard to make sense of.

As you can see, there's more work to do to reduce the memory usage for the graph, but for our repo at work this PR makes it usable already, which it wasn't really before.

codacy-production[bot] commented 1 week ago

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 5a5cd849d18779ff8f2d057a70550fa737a238fc[^1] :white_check_mark: 75.61%
Coverage variation details | | Coverable lines | Covered lines | Coverage | | ------------- | ------------- | ------------- | ------------- | | Common ancestor commit (5a5cd849d18779ff8f2d057a70550fa737a238fc) | Report Missing | Report Missing | Report Missing | | | Head commit (deee5fa95781bb515db539999394d651c8ba31c6) | 52182 | 45140 | 86.50% | **Coverage variation** is the difference between the coverage for the head and common ancestor commits of the pull request branch: ` - `
Diff coverage details | | Coverable lines | Covered lines | Diff coverage | | ------------- | ------------- | ------------- | ------------- | | Pull request (#3687) | 123 | 93 | **75.61%** | **Diff coverage** is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: `/ * 100%`

See your quality gate settings    Change summary preferences


:rocket: Don’t miss a bit, follow what’s new on Codacy.

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more [^1]: Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.