lazygit: Checking out thousands of changes is slow for large repos
Describe the bug A clear and concise description of what the bug is.
Checking out between branches is way to slow for large branches.
To Reproduce Steps to reproduce the behavior:
- Use nixpkgs as an example
- clone it
- Add the 25.11 branch and checkout between them.
Expected behavior A clear and concise description of what you expected to happen.
It should really not be as this slow.
Screenshots If applicable, add screenshots to help explain your problem.
Version info:
- Lazygit:
commit=, build date=, build source=nix, version=0.50.0, os=darwin, arch=arm64, git version=2.49.0 - Git:
2.49.0
Additional context
May 24 22:24:57 |DEBU| RunCommand command="git checkout master"
May 24 22:24:59 |INFO| git checkout master (1.683055292s)
May 24 22:24:59 |INFO| refreshing all scopes in block-ui mode
May 24 22:24:59 |INFO| Refresh took 10.042µs
May 24 22:24:59 |DEBU| RunCommand command="git stash list -z --pretty=%ct|%gs"
May 24 22:24:59 |DEBU| RunCommand command="git tag --list -n --sort=-creatordate"
May 24 22:24:59 |INFO| refreshed merge conflicts in 16.209µs
May 24 22:24:59 |DEBU| using cache for key status.showUntrackedFiles
May 24 22:24:59 |DEBU| RunCommand command="git status --untracked-files=all --porcelain -z --find-renames=50%"
May 24 22:24:59 |INFO| git stash list -z --pretty=%ct|%gs (11.563375ms)
May 24 22:24:59 |INFO| git tag --list -n --sort=-creatordate (11.591333ms)
May 24 22:24:59 |INFO| postRefreshUpdate for tags took 9.042µs
May 24 22:24:59 |INFO| refreshed tags in 11.860083ms
May 24 22:24:59 |INFO| git for-each-ref --sort=refname --format=%(refname:short) refs/remotes (11.621916ms)
May 24 22:24:59 |INFO| postRefreshUpdate for remotes took 19µs
May 24 22:24:59 |INFO| postRefreshUpdate for remoteBranches took 3.792µs
May 24 22:24:59 |INFO| refreshed remotes in 11.984583ms
May 24 22:24:59 |INFO| postRefreshUpdate for stash took 44.208µs
May 24 22:24:59 |INFO| refreshed stash in 12.026208ms
May 24 22:24:59 |INFO| git -c log.showSignature=false log -g --abbrev=40 --format=%h%x00%ct%x00%gs%x00%P (12.057125ms)
May 24 22:24:59 |INFO| postRefreshUpdate for reflogCommits took 213.917µs
May 24 22:25:00 |INFO| git status --untracked-files=all --porcelain -z --find-renames=50% (604.383375ms)
May 24 22:25:00 |INFO| refreshed files in 605.107708ms
May 24 22:25:00 |INFO| refreshed staging in 605.204208ms
May 24 22:25:00 |INFO| git log HEAD --topo-order --oneline --pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s --abbrev=40 -300 --no-show-signature -- (3.927187125s)
May 24 22:25:00 |DEBU| Error getting git config value for key: rebase.updateRefs. Error: the key is not found for [git config --get --null rebase.updateRefs]
May 24 22:25:00 |INFO| postRefreshUpdate for commits took 6.886709ms
May 24 22:25:00 |DEBU| using cache for key rebase.updateRefs
May 24 22:25:00 |DEBU| RunCommand command="git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads"
May 24 22:25:00 |DEBU| RunCommand command="git rev-parse --abbrev-ref --verify HEAD"
May 24 22:25:00 |INFO| git rev-parse --abbrev-ref --verify HEAD (5.811416ms)
May 24 22:25:00 |DEBU| RunCommand command="git merge-base master master@{u}"
May 24 22:25:00 |DEBU| RunCommand command="git merge-base HEAD refs/remotes/origin/master"
May 24 22:25:00 |INFO| git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads (8.345292ms)
May 24 22:25:00 |DEBU| RunCommand command="git worktree list --porcelain"
May 24 22:25:00 |INFO| git merge-base master master@{u} (7.074875ms)
May 24 22:25:00 |INFO| git merge-base HEAD refs/remotes/origin/master (8.179375ms)
May 24 22:25:00 |INFO| git worktree list --porcelain (5.933958ms)
May 24 22:25:00 |DEBU| RunCommand command="git -C /Users/eveeifyeve/github/eveeifyeve/nixpkgs rev-parse --path-format=absolute --absolute-git-dir"
May 24 22:25:00 |INFO| git -C /Users/eveeifyeve/github/eveeifyeve/nixpkgs rev-parse --path-format=absolute --absolute-git-dir (5.216458ms)
May 24 22:25:00 |INFO| postRefreshUpdate for worktrees took 53.083µs
May 24 22:25:00 |DEBU| RunCommand command="git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium refs/heads/master --"
May 24 22:25:00 |INFO| postRefreshUpdate for localBranches took 197.125µs
May 24 22:25:02 |INFO| refreshing the following scopes in sync mode: files
May 24 22:25:02 |INFO| Heap memory in use: 103.7 MB
May 24 22:25:02 |DEBU| using cache for key status.showUntrackedFiles
May 24 22:25:02 |INFO| refreshed merge conflicts in 26.625µs
May 24 22:25:02 |DEBU| RunCommand command="git status --untracked-files=all --porcelain -z --find-renames=50%"
May 24 22:25:03 |INFO| git status --untracked-files=all --porcelain -z --find-renames=50% (559.366209ms)
May 24 22:25:03 |INFO| refreshed files in 559.706625ms
May 24 22:25:03 |INFO| Refresh took 560.21425ms
May 24 22:25:03 |INFO| git log HEAD --topo-order --oneline --pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s --abbrev=40 -300 --no-show-signature -- (3.754516458s)
May 24 22:25:03 |DEBU| using cache for key rebase.updateRefs
May 24 22:25:03 |INFO| postRefreshUpdate for commits took 644.167µs
May 24 22:25:03 |INFO| refreshed commits and commit files in 4.430693458s
May 24 22:25:03 |DEBU| using cache for key rebase.updateRefs
May 24 22:25:03 |INFO| refreshed reflog and branches in 4.431357375s
May 24 22:25:03 |INFO| postRefreshUpdate for submodules took 3µs
May 24 22:25:03 |INFO| postRefreshUpdate for files took 3.917µs
May 24 22:25:03 |INFO| postRefreshUpdate for submodules took 917ns
May 24 22:25:03 |INFO| postRefreshUpdate for files took 1µs
May 24 22:25:03 |DEBU| using cache for key rebase.updateRefs
May 24 22:25:03 |DEBU| using cache for key rebase.updateRefs
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 16
Turns out the
git for-each-refis slow when it deals with heavily outdated branches. I had two branches that I rebased locally, but didn’t push. They were both ahead of upstream by about 8k commits. And a third branch that was waay behind upstream. Removing the remotes for those 3, makes the UI super fast again!So, my takeaways for working with very big repos at the scale of nixpkgs:
--graphfrombranchLogCmdandallBranchesLogCmds- otherwise git log in the main view will be slow like a snail.git.log.order = default, otherwise the commit log will be really slow. No date-order, no topo-order 😕I think it would still be good to not freeze on
git for-each-ref, outdated branches shouldn’t take lazygit down like that. If that could run async in the background… that would be much better.The 40s seemed to have been an outlier, maybe there was some fetch going on at the same or so. But I consistently get something between 5-10s.
Some stuff from the logs:
The
--date-orderseems to be a problem for me. Removing that improves thegit logcommand significantly - I explicitly need to set it to “default”, not to topo-order, though. I can see that the log view loads much quicker on startup. I also updated from 0.50.0 to 0.51.1, which seems to have helped a little bit.Still - entering a rebase or checking out a different branch freezes the UI for me for a few seconds. I noticed the “Local branches” view takes very long to load on initial startup. I assume that’s related to the
git for-each-refabove taking 7-8 seconds?what is slowing it down is the
git status --untracked-files=all --porcelain -z --find-renames=50%While hyperfine is a great benchmarking tool, it’s no good in this case, because checking out the same branch again when it is already checked out is fast of course.
You might just use
time git checkout master(if the other branch is checked out).But the result seems to be pretty close to what lazygit’s log said (1.6s). Are you saying that the interaction in lazygit (from pressing space until you see the new branch in the commits panel) is significantly slower than that?