Skip to content

perf: skip untracked file enumeration when staging hunks of tracked files#5466

Closed
renezander030 wants to merge 1 commit intojesseduffield:masterfrom
renezander030:perf/skip-untracked-on-staging-refresh
Closed

perf: skip untracked file enumeration when staging hunks of tracked files#5466
renezander030 wants to merge 1 commit intojesseduffield:masterfrom
renezander030:perf/skip-untracked-on-staging-refresh

Conversation

@renezander030
Copy link
Copy Markdown

Summary

  • When staging hunks in the staging panel, git status --untracked-files=all runs on every refresh. In large repos (275k+ files) this causes multi-second delays after each staging operation.
  • Since staging hunks of a tracked file cannot affect untracked files, this PR skips their enumeration by using --untracked-files=no and preserving untracked files from the previous model state.
  • The optimization only applies when the selected file is tracked. Staging untracked files (??) still triggers a full refresh to capture the ?? > AM transition correctly.

Test plan

  • go build ./... compiles
  • go test ./pkg/commands/git_commands/... ./pkg/gui/... passes
  • Manual: stage hunks in a large repo, verify snappy response
  • Manual: stage the first hunk of a new untracked file, verify it transitions to AM correctly
  • Manual: verify untracked files remain visible in the files panel after staging tracked hunks

Fixes #5455

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 3, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

…iles

When staging hunks in the staging panel, lazygit refreshes the files
list by running git status --untracked-files=all. In large repos (e.g.
275k files) this directory walk dominates the refresh time, causing
multi-second delays after each staging operation.

Since staging hunks of a tracked file cannot change the set of
untracked files, we can safely skip their enumeration by using
--untracked-files=no and preserving the untracked files from the
previous model state.

The optimization is only applied when the file being staged is tracked.
Staging an untracked file (status ??) still triggers a full refresh to
correctly capture the ?? to AM transition.

Fixes jesseduffield#5455
@renezander030 renezander030 force-pushed the perf/skip-untracked-on-staging-refresh branch from f89d6e9 to 25cced3 Compare April 6, 2026 13:06
@stefanhaller
Copy link
Copy Markdown
Collaborator

I'm not interested in reviewing AI generated PRs. Closing.

@renezander030
Copy link
Copy Markdown
Author

Understood. For what it's worth, the fix came from debugging a real performance issue I hit while using lazygit on a large monorepo. But I respect the policy. Thanks for maintaining the project!

@stefanhaller
Copy link
Copy Markdown
Collaborator

In this case you might try this PR and see if it helps with your monorepo. Please report your findings. I'd also be interested in your answer to this question because I haven't been able to reproduce the issue myself with various large test repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

staging hunks or files is slow in a large repo

2 participants