Skip to content

Fix delay with flicking through files or commits when git diff is very slow #4803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2025

Conversation

stefanhaller
Copy link
Collaborator

@stefanhaller stefanhaller commented Aug 8, 2025

One reason why git diff can be very slow is when "diff.algorithm = histogram" is being used. In this case, showing a very long single-file diff can take seconds to load, and you'll see the "loading..." message in the main view until we got the first lines of the diff to show. There's nothing really we can do about this delay; however, when switching to another, shorter file (or commit) while the "loading..." message is still showing, this switch should be instantaneous. And it was before 0.54.0, but we broke this in 0.54.0 with 8d7740a (#4782); now users have to wait for the slow git diff command to output more text before the switch occurs. To fix this, don't block waiting for the process to terminate if we just stopped it.

In addition, improve CPU usage by terminating git processes gracefully (by sending them a TERM signal); this helps keep CPU usage low when flicking through several of these huge diffs with "diff.algorithm = histogram", because it avoids having several git processes running in the background, calculating expensive diffs that we are never going to show. Unfortunately this is only possible on Linux and Mac, so Windows users will have to live with the higher CPU usage. The recommended workaround is to not use "diff.algorithm = histogram".

Fixes #4798.

Copy link

codacy-production bot commented Aug 8, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 77a92071 65.79%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (77a9207) Report Missing Report Missing Report Missing
Head commit (e056e33) 57237 49738 86.90%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4803) 38 25 65.79%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  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.

@stefanhaller stefanhaller force-pushed the improve-ui-lag-for-very-slow-git-diff-commands branch from cde15d5 to 2a1fb18 Compare August 9, 2025 10:15
No need to do a runtime check if we already have the platform-specific files.
…y slow

One reason why git diff can be very slow is when "diff.algorithm = histogram" is
being used. In this case, showing a very long single-file diff can take seconds
to load, and you'll see the "loading..." message in the main view until we got
the first lines of the diff to show. There's nothing really we can do about this
delay; however, when switching to another, shorter file (or commit) while the
"loading..." message is still showing, this switch should be instantaneous. And
it was before 0.54.0, but we broke this in 0.54.0 with 8d7740a (#4782); now
users have to wait for the slow git diff command to output more text before the
switch occurs.

To fix this, don't block waiting for the process to terminate if we just stopped
it.
The previous commit already fixed the user-visible lag, but there's still a
problem with multiple background git processes consuming resources calculating
diffs that we are never going to show. Improve this by terminating those
processes (by sending them a TERM signal).

Unfortunately this is only possible on Linux and Mac, so Windows users will have
to live with the higher CPU usage. The recommended workaround is to not use
"diff.algorithm = histogram".
@stefanhaller stefanhaller force-pushed the improve-ui-lag-for-very-slow-git-diff-commands branch from 2a1fb18 to e056e33 Compare August 11, 2025 16:11
@stefanhaller stefanhaller enabled auto-merge August 11, 2025 16:11
@stefanhaller stefanhaller merged commit b1382da into master Aug 11, 2025
13 checks passed
@stefanhaller stefanhaller deleted the improve-ui-lag-for-very-slow-git-diff-commands branch August 11, 2025 16:13
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 12, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | patch | `v0.54.1` -> `v0.54.2` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.54.2`](https://github.com/jesseduffield/lazygit/releases/tag/v0.54.2)

[Compare Source](jesseduffield/lazygit@v0.54.1...v0.54.2)

<!-- Release notes generated using configuration in .github/release.yml at v0.54.2 -->

Here's another point release; this one fixes a performance regression in 0.54.0 that made flicking through diffs a little less snappy (or a lot less, in some scenarios) than it could be.

For the changes in 0.54.0, see https://github.com/jesseduffield/lazygit/releases/tag/v0.54.0.

#### What's Changed

##### Fixes 🔧

- Fix scrollbar in certain popup panels (e.g. the intro message for new users) by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4804
- Fix delay with flicking through files or commits when git diff is very slow by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4803

##### Maintenance ⚙️

- Stop bumping our homebrew formula by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4799
- Update the badges of golangci-lint and homebrew in `README.md` by [@&#8203;kyu08](https://github.com/kyu08) in jesseduffield/lazygit#4807

##### Docs 📖

- Fix the useHunkModeInStagingView hint in the breaking changes message by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4800
- Update `CONTRIBUTING.md` to clarify translation contribution process by [@&#8203;kyu08](https://github.com/kyu08) in jesseduffield/lazygit#4806

**Full Changelog**: jesseduffield/lazygit@v0.54.1...v0.54.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS42MS4xIiwidXBkYXRlZEluVmVyIjoiNDEuNjEuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update of diff for files can take a long time in large repos with significant number of changes
1 participant