Skip to content

perf(gui): target refreshes after push, pull, and fetch - #50

Open
HiFiveJazz wants to merge 9 commits into
Blankeos:mainfrom
HiFiveJazz:perf/targeted-push-refresh
Open

HiFiveJazz wants to merge 9 commits into
Blankeos:mainfrom
HiFiveJazz:perf/targeted-push-refresh

Conversation

@HiFiveJazz

@HiFiveJazz HiFiveJazz commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Avoid full repo refreshes after successful push, pull, and fetch operations when only a subset of the model can have changed.

Instead:

  • push refreshes:
    • local branches
    • remote-tracking branches
    • remote metadata
    • pushed/unpushed commit status
  • pull uses a targeted streaming refresh
  • pull avoids redundant remote tag queries after the remote update
  • fetch refreshes only:
    • branches
    • commits
    • remotes
    • tags
  • background auto-fetch reuses the same targeted fetch refresh when refs change

Fetch-and-checkout and unrelated remote operations keep the existing full refresh behavior where HEAD/worktree state may have changed.

Why

Remote operations often set needs_refresh = true, which schedules a full repo refresh, which is expensive especially on big projects that use git like the Linux Kernel, leaving a lot performance to be desired.

The goal here is to keep the existing Git CLI architecture, but make refreshes operation-specific instead of blindly reloading the whole model.

Benchmarks

All Linux kernel measurements below were taken against the same checkout/configuration using strace.

Push

Using a local repo as the push target so the benchmark mostly isolates lazygitrs refresh work:

Metric Before After Improvement
Git commands after push 26 5 80.8% fewer
Remote tag queries after push 2 0 eliminated
Post-push refresh latency ~1.97 s ~17.8 ms ~111Γ— faster
Push-to-settled latency ~2.11 s ~141 ms ~14.9Γ— faster

This optimizes the refresh work performed after git push completes.

Pull

The targeted pull refresh reduced the post-pull command set from:

Metric Before Targeted pull Improvement
Git commands after pull 28 22 21.4% fewer
Traced post-pull refresh ~1.43 s ~1.14 s ~20.4% lower
Pull-to-last-refresh-child ~1.80 s ~1.53 s ~15.3% lower

The improvement comes from avoiding unrelated model reloads afterward.

The follow-up tag optimization also removes the remote tag discovery work that still remained in the targeted pull path:

  • git remote
  • one git ls-remote --tags <remote> per configured remote

With three configured remotes, that removed another 4 Git commands from the traced operation, though there are more ways to optimize pull still that I'm looking into.

Fetch

The targeted fetch path refreshes only branches, commits, remotes, and tags.

Metric Before After Improvement
Git commands after fetch 28 8 71.4% fewer
Remote tag queries 3 0 eliminated
Median post-fetch refresh latency ~1.46 s ~772 ms ~47.2% lower / ~1.90Γ— faster
Median fetch-to-settled latency ~1.53 s ~907 ms ~40.9% lower / ~1.69Γ— faster

The raw git fetch itself is unchanged; this measures the refresh work
performed after it completes.

Background Auto-fetch

When periodic auto-fetch reports that refs changed, it now reuses the same targeted fetch refresh instead of scheduling a full model refresh.

This reduces recurring background work while lazygitrs is left open.

Correctness

  • pull retains the existing commit filtering and unpushed-status behavior
  • fetch-and-checkout keeps the full refresh path because it may change HEAD/worktree state
  • added regression coverage for targeted push, pull, fetch, and auto-fetch refresh behavior
  • full test suite passes
  • cargo fmt --check passes
  • git diff --check passes

@HiFiveJazz
HiFiveJazz force-pushed the perf/targeted-push-refresh branch from ce79f77 to 9fdf274 Compare October 12, 2026 03:57
@HiFiveJazz HiFiveJazz changed the title perf(gui): avoid full refresh after push perf(gui): target refreshes after push, pull, and fetch Oct 12, 2026
@Blankeos

Blankeos commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

perf/targeted-push-refresh β†’ main
Model: claude-sonnet-5-5, effort unknown

Confidence: 3.5/5

The push/pull/fetch/auto-fetch targeting is correct in everything I ran and cuts git commands a lot. Two things hold it back: it silently stops the periodic refresh from picking up external changes (reproduced), and it now conflicts with main.
Confidence bumps: keep branches/commits/HEAD in the periodic refresh (or make it configurable) β†’ 4.5/5; rebase onto main (conflicts in controller/branches.rs and controller/files.rs from #44) and re-run tests β†’ 5/5.

Checks run

  • cargo fmt --check clean. cargo test: 382 passed, 0 failed. cargo clippy: only pre-existing warnings.
  • Mergeability: CONFLICTING against current main (6dba4a0 β†’ 73356c8). Conflicts in src/gui/controller/branches.rs and files.rs (plus an auto-merge in remotes.rs); start_remote_op's new first argument also hits any call site added by main.
  • Ran main-at-merge-base and this PR as release builds in a pty against a synthetic repo (20,000 commits, 2,000 tags, 300 branches, local bare origin; second clone pushing). A git shim logged every command the app ran. Medians of 5 runs unless noted.
Scenario main PR
Git commands after push (P β†’ p) 26 6
Git commands after fetch (f) 26 8
Git commands after pull (p β†’ p) 25 17
Fetch: last git command after keypress 0.56 s 0.48 s
Pull: last git command after keypress 0.81 s 0.69 s
Push: last git command after keypress 0.94 s 0.90 s
Idle, auto-fetch + refresh every 3 s, 20 s, no changes: commands 295 19
Same idle window: CPU 0.79 s 0.38 s
  • Time-to-visible (status ↓1 / ↑ cleared) was the same, 0.06–0.4 s, on both. The wall-clock gain on my repo is small (~0.1 s) because local-remote git is fast; the command reduction is the real win and should scale with repo size as in Jazz's kernel numbers (which I can't reproduce here).
  • Correctness after each action, checked against git status -sb:
    • push: ↑2 cleared, origin/master matches.
    • fetch: ↓1 appears, new tag shows in the Tags tab.
    • pull: ↓1 clears and the new commit is in the list.
    • auto-fetch (3 s interval): ↓1 after ~2.2 s and the new tag appears, on both.
  • Checkout via the Branches panel (with and without an active commit filter): HEAD, status and the commit list were identical to main.
  • Rebase in progress (conflicted c.txt) followed by a fetch: the rebase status line stayed, and status matches git status. No difference from main.
  • Periodic refresh: regression reproduced. With refreshInterval: 3, an external git commit, git branch and git checkout -b in the same repo appeared in the app after 2.2 s on main. On this PR they never appeared in 14 s (commit, new branch and new HEAD all stale).

Summary

Thanks Jazz, the targeted refresh holds up. Push drops from 26 to 6 git commands, fetch from 26 to 8, and the background auto-fetch idle cost falls from 295 commands per 20 s to 19, all still correct against git status. What I'd change before merging:

  1. Periodic refresh: this is a visible behavior change that isn't in the description. After this PR, commits, branches and HEAD changed from another terminal never show up until the user presses R. I'd keep the cheap targeted set but include branches, HEAD and commits in start_background_periodic_refresh, or gate it behind a config flag.
  2. Rebase onto main: it conflicts with refactor: centralize matches_key in keybindings and make char matching case-insensitiveΒ #44 in controller/branches.rs and controller/files.rs.
  3. Scope: the checkout and periodic changes are outside the title. If they stay, mention them in the description. I verified checkout is equivalent to main, so I'm not asking for a split on that alone.
  4. Smaller: refresh_after_push still runs three loads synchronously on the UI thread. I couldn't make it stall locally, but a slow remote disk could.

Map

flowchart LR
  ctl[controller/*.rs: pass RemoteOpKind] --> start[Gui::start_remote_op]
  start --> recv[receive_remote_op_results]
  recv -->|Push| push[refresh_after_push, sync]
  recv -->|Pull| pull[start_background_pull_refresh]
  recv -->|Fetch / autofetch| fetch[start_background_fetch_refresh]
  recv -->|checkout| co[start_background_checkout_refresh]
  tick[main loop periodic] --> per[start_background_periodic_refresh]
  pull --> gm[git/mod.rs load_model_after_*_streaming]
  fetch --> gm
  co --> gm
  per --> gm
  gm --> tag[git/tag.rs load_tags_after_remote_update]
  gm --> cm[git/commit.rs apply_checkout_head_state]
Loading

Start at receive_remote_op_results in src/gui/mod.rs.

Regressions

  • Periodic refresh no longer reloads branches, commits, HEAD, stash or reflog: external changes stay stale until R (reproduced above).
  • Push refresh runs synchronously on the UI thread and skips tags and after_model_refresh.
  • Tag on_remote can go stale after pull/fetch (new tags are assumed remote; remote-deleted tags aren't cleared).
  • Merge conflicts with current main (see Checks run).

Migrations

None. No config, keybinding or format changes.

Before merging

  • Restore (or make configurable) external-change pickup in the periodic refresh
  • Rebase onto main and re-run cargo test / cargo fmt
  • Mention checkout and periodic changes in the PR description

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