From 0a9ca18309e075c37f34b25766d5249d3a83c818 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Thu, 18 Sep 2025 14:44:36 +0200 Subject: [PATCH] gui: presentation: commits: limit pipeset (pre-)rendering Limit the number of (pre-)rendered pipesets which are visible when rendering a git graph to the actual currently visible number of commits. This is important for large repositories with a large number of commits when scrolling past the first 200 commits, which currently triggers a load of the complete commit history[1]. If this happens and the git graph rendering is enabled a potentially large number of pipes (~138k for the linux kernel) is allocated. [1]: https://github.com/jesseduffield/lazygit/blob/d56a9cf73e6a34550e42d2627c011c4b73e5a975/pkg/gui/controllers/local_commits_controller.go#L1265 Signed-off-by: Stefan Kerkmann --- pkg/gui/presentation/commits.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index a5799bcb333..0a0ce722b9b 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -76,7 +76,8 @@ func GetCommitListDisplayStrings( bisectBounds := getbisectBounds(commits, bisectInfo) // function expects to be passed the index of the commit in terms of the `commits` slice - var getGraphLine func(int) string + getGraphLine := func(int) string { return "" } + if showGraph { if len(commits) > 0 && commits[0].Divergence != models.DivergenceNone { // Showing a divergence log; we know we don't have any rebasing @@ -107,9 +108,9 @@ func GetCommitListDisplayStrings( allGraphLines = append(allGraphLines, graphLines...) } } - if localSectionStart < len(commits) { + if localSectionStart < len(commits) && localSectionStart < endIdx { // we have some local commits - pipeSets := loadPipesets(commits[localSectionStart:]) + pipeSets := loadPipesets(commits[localSectionStart:endIdx]) if localSectionStart < endIdx { // some of the local commits are visible graphOffset := max(startIdx, localSectionStart) @@ -128,12 +129,12 @@ func GetCommitListDisplayStrings( getGraphLine = func(idx int) string { return allGraphLines[idx-startIdx] } - } else { + } else if rebaseOffset < endIdx { // this is where the graph begins (may be beyond the TODO commits depending on startIdx, // but we'll never include TODO commits as part of the graph because it'll be messy) graphOffset := max(startIdx, rebaseOffset) - pipeSets := loadPipesets(commits[rebaseOffset:]) + pipeSets := loadPipesets(commits[rebaseOffset:endIdx]) pipeSetOffset := max(startIdx-rebaseOffset, 0) graphPipeSets := pipeSets[pipeSetOffset:max(endIdx-rebaseOffset, 0)] graphCommits := commits[graphOffset:endIdx] @@ -149,8 +150,6 @@ func GetCommitListDisplayStrings( return "" } } - } else { - getGraphLine = func(int) string { return "" } } // Determine the hashes of the local branches for which we want to show a