Skip to content

Conversation

@MaxFangX
Copy link
Contributor

@MaxFangX MaxFangX commented Dec 4, 2025

When opening a diff view, vgit runs several git commands to gather file state. Two of these can be optimized:

First, git rev-parse --show-toplevel (repo discovery) is called frequently but the result never changes for a given directory during a session. This is now cached per-directory. Edge case: if a user runs git init in a new location during a session, the cache would be stale - rare enough that we accept it rather than add invalidation complexity.

Second, the per-file conflict checks (git ls-files -u and git status) are only relevant during merge/rebase/cherry-pick operations. We now gate these with git_conflict.status(), which only checks for files like .git/MERGE_HEAD - fast filesystem checks, no git commands. In the common case (no active merge), this skips 2 git commands.

Together these reduce git commands from 5 to 2 when opening a diff view (60% reduction).

@MaxFangX MaxFangX force-pushed the 2025-12-04-diff-screen-enter-latency branch from e0492a6 to cc84144 Compare December 5, 2025 01:09
Cache the result of git rev-parse --show-toplevel per directory. The
repo root for a given path never changes during a session, so we can
safely cache it after the first lookup. This eliminates a git command on
every diff view open and other operations that need to discover the
repo.
Skip expensive per-file conflict checks (git ls-files -u and git status)
when not in a merge/rebase/cherry-pick state. Use git_conflict.status()
which only checks for files like .git/MERGE_HEAD - fast filesystem
checks, no git commands.

In the common case (no active merge), this eliminates 2 git commands
when opening a diff view.
@MaxFangX MaxFangX force-pushed the 2025-12-04-diff-screen-enter-latency branch from cc84144 to 3d5e4e3 Compare December 5, 2025 20:36
@MaxFangX
Copy link
Contributor Author

MaxFangX commented Dec 5, 2025

Rebased.

@tanvirtin tanvirtin merged commit 5990a99 into tanvirtin:main Dec 6, 2025
1 of 2 checks passed
@MaxFangX MaxFangX deleted the 2025-12-04-diff-screen-enter-latency branch December 6, 2025 18:25
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.

2 participants