Skip to content

Commit 0a9ca18

Browse files
committed
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 <[email protected]>
1 parent 1fd771f commit 0a9ca18

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pkg/gui/presentation/commits.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func GetCommitListDisplayStrings(
7676
bisectBounds := getbisectBounds(commits, bisectInfo)
7777

7878
// function expects to be passed the index of the commit in terms of the `commits` slice
79-
var getGraphLine func(int) string
79+
getGraphLine := func(int) string { return "" }
80+
8081
if showGraph {
8182
if len(commits) > 0 && commits[0].Divergence != models.DivergenceNone {
8283
// Showing a divergence log; we know we don't have any rebasing
@@ -107,9 +108,9 @@ func GetCommitListDisplayStrings(
107108
allGraphLines = append(allGraphLines, graphLines...)
108109
}
109110
}
110-
if localSectionStart < len(commits) {
111+
if localSectionStart < len(commits) && localSectionStart < endIdx {
111112
// we have some local commits
112-
pipeSets := loadPipesets(commits[localSectionStart:])
113+
pipeSets := loadPipesets(commits[localSectionStart:endIdx])
113114
if localSectionStart < endIdx {
114115
// some of the local commits are visible
115116
graphOffset := max(startIdx, localSectionStart)
@@ -128,12 +129,12 @@ func GetCommitListDisplayStrings(
128129
getGraphLine = func(idx int) string {
129130
return allGraphLines[idx-startIdx]
130131
}
131-
} else {
132+
} else if rebaseOffset < endIdx {
132133
// this is where the graph begins (may be beyond the TODO commits depending on startIdx,
133134
// but we'll never include TODO commits as part of the graph because it'll be messy)
134135
graphOffset := max(startIdx, rebaseOffset)
135136

136-
pipeSets := loadPipesets(commits[rebaseOffset:])
137+
pipeSets := loadPipesets(commits[rebaseOffset:endIdx])
137138
pipeSetOffset := max(startIdx-rebaseOffset, 0)
138139
graphPipeSets := pipeSets[pipeSetOffset:max(endIdx-rebaseOffset, 0)]
139140
graphCommits := commits[graphOffset:endIdx]
@@ -149,8 +150,6 @@ func GetCommitListDisplayStrings(
149150
return ""
150151
}
151152
}
152-
} else {
153-
getGraphLine = func(int) string { return "" }
154153
}
155154

156155
// Determine the hashes of the local branches for which we want to show a

0 commit comments

Comments
 (0)