Skip to content

perf(gui): coalesce diff refresh after staging - #49

Merged
Blankeos merged 2 commits into
Blankeos:mainfrom
HiFiveJazz:perf/coalesce-stage-diff-refresh
Nov 5, 2026
Merged

Blankeos merged 2 commits into
Blankeos:mainfrom
HiFiveJazz:perf/coalesce-stage-diff-refresh

Conversation

@HiFiveJazz

@HiFiveJazz HiFiveJazz commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR avoids eagerly refreshing the diff immediately after optimistic stage/unstage updates.

The existing stage/unstage flow already does a pretty good job of doing status-only refresh after the background Git operation completes, and that refresh schedules a diff update using authoritative repository state. However, setting needs_diff_refresh before the Git operation completes causes the same mutable diff to be generated twice, which is unnecessary

This removes those three eager diff invalidations for:

  • individual file stage/unstage
  • directory stage/unstage
  • stage-all/unstage-all

The optimistic file-status update remains unchanged, so staging still updates the file list immediately.

Performance

Measured with strace -f -e trace=execve, with auto-refresh and auto-fetch disabled.

Stage-all + unstage-all:

  • Before: 48 Git subprocesses
  • After: 44 Git subprocesses
  • Reduction: 8.3%

Single-file stage + unstage:

  • Before: 44 Git subprocesses
  • After: 42 Git subprocesses
  • Reduction: 4.5%

The removed subprocesses are the redundant diff previews issued before the authoritative status refresh. The later diff refresh after git status --porcelain -uall remains. I tested this using cargo test and saw no regressions.

@Blankeos

Blankeos commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

perf/coalesce-stage-diff-refresh → main
Model: claude-sonnet-5-5, effort unknown

Confidence: 5/5

Ran cargo test on the branch with my follow-up commit: 371 passed, 0 failed. Traced the stage/unstage paths for stale-diff cases; the one gap is fixed in 9d630e1.
Confidence bumps: none left. Everything I'd have asked for was run.

Summary

Update: I pushed 9d630e1 to this branch (maintainer edit). When the status refresh fails or its worker dies, receive_files_refresh now still sets needs_diff_refresh, since the eager flag that used to cover that case is gone. I added an assertion to the existing failed-refresh test. Opus reviewed the approach and found no other path that leaves the diff stale.

Thanks @HiFiveJazz, nice and focused. Removing the eager needs_diff_refresh = true in toggle_stage (file and dir) and toggle_stage_all is safe as far as I can tell: receive_files_refresh in src/gui/mod.rs sets needs_diff_refresh = true once the status-only refresh lands (or the follow-up start_files_refresh_async does, via the full load completion), so the diff is still reloaded from authoritative state. Selection changes still invalidate via last_diff_key. Only nit: if the status refresh errors (Ok(Err(_)) branch) no diff refresh is queued any more; previously the eager flag covered that. That is an error path that already shows a popup, so I would not block on it. The measured saving (2-4 git subprocesses per action) is modest but real.

Map

flowchart LR
  A[controller/files.rs toggle_stage / toggle_stage_all] --> B[gui/mod.rs enqueue_stage_then_refresh]
  B --> C[git stage/unstage thread]
  C --> D[refresh_files_status_only]
  D --> E[receive_files_refresh]
  E --> F[needs_diff_refresh = true]
  F --> G[begin_diff_request]
Loading

Regressions

  • Brief window where the diff pane shows the pre-op diff until the git op finishes (was already stale before, since the eager reload raced the background git op).
  • If the status refresh fails, the diff is not reloaded (minor, error already surfaced).
  • Otherwise none found.

Migrations

None. No config, keybinding, or format change.

Before merging

@Blankeos Blankeos left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after review and checks (see the pr-review comment).

@Blankeos
Blankeos merged commit 97ccd9e into Blankeos:main Nov 5, 2026
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