Repository navigation
perf(list): cold-start primer for the Remote⇅ column, per-upstream-group - #2718
Conversation
Mirrors the `main↕` primer from #2704 for the `Remote⇅` column. On a cold cache, `Repository::prime_upstream_ahead_behind_cache` runs one `for-each-ref %(ahead-behind:UPSTREAM_SHA)` walk per unique upstream SHA (scoped to that upstream's branches) and bulk-writes the `ahead-behind/` cache. Per-row `UpstreamTask::compute` then reads the cache via `ahead_behind_by_sha` instead of falling through to per-branch `compute_ahead_behind` (merge-base + 2× rev-list). Wired into the post-skeleton `rayon::scope`, nested inside the snapshot spawn so it reads the snapshot's already-scanned local/remote inventories — no extra `for-each-ref refs/remotes/` fork on the warm path. Candidates scoped to branches that will actually render an `UpstreamTask` row (worktree-attached when `!show_branches`), and the primer honors `list.task-timeout-ms` via `set_command_timeout`. Cache-correctness defenses match #2704: `%(ahead-behind:UPSTREAM_SHA)` (not `:refname`) so git counts against the SHA the cache will be keyed by; cache key uses the `%(objectname)` git reports in the same walk; writes flow through `put_ahead_behind_bulk` for one `sweep_lru` at the end; orphan branches normalize to `(0, 0)` via per-upstream memoized `rev-list --count`. Known limitation, documented in the primer docstring: when every branch tracks its own remote (distinct upstream SHA per branch), every group has size 1 and the primer skips all of them — those fall through to the per-row parallel path. A `%(upstream:track)` walk could batch them, but git computes that atom against the upstream's current value at walk time, which we can't pin to the SHA the cache will be keyed by — the resulting race would break the cache invariant `compute_ahead_behind` establishes on a miss. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch is failing, but most of it is a stale base-pointer artifact rather than a real coverage gap.
Why codecov reports 58 missed lines in ref_snapshot.rs: codecov set its base for this PR to bfb117a6 (the commit before #2704 merged), so every line #2704 added to ref_snapshot.rs is being charged to this PR's patch. The actual merge-base in git is 5384f62b. You can see this in the commit_uploads API response: "parent": "bfb117a665bd68df3abcd56cda0ea3d0b3d36ceb" even though git merge-base origin/main remote-ahead-behind-batch returns 5384f62b.
Mixed in: a handful of lines inside the new function (412 base_total = ... or_insert_with(...), 415 .and_then(|s| s.trim().parse().ok()), 437 writes.iter().map(...)) appear twice in cobertura.xml — once with hits (1, 1, 10 respectively) and once with hits="0". Codecov picks the 0-hit entry. This is the cargo-llvm-cov "N functions have mismatched data" issue (LLVM #97574) already documented in CLAUDE.md.
Actual coverage from cobertura.xml for the new function (lines 348-440):
- Function body: 408–417 hit, 425/428/430 hit 10× per group, 434–439 hit 76× — the success path is well-tested.
- Untested branches: line 410 (
git < 2.36 or batch failed) and line 419 (fresh.getmiss) — both are defensive paths that won't fire on CI's git. - Line 426 (
(0, 0)orphan arm) is genuinely 0 hits in cobertura, even thoughprime_upstream_normalizes_orphan_to_zerolooks like it should exercise it. Worth a glance — possible that the orphan branch isn't reachingcold_by_upstreamfor some reason (e.g. its upstream resolves to a different SHA than the other 9, dropping it into a size-1 group below threshold).
Dismissing the approval per the CLAUDE.md "never merge with failing codecov/patch without explicit user approval" rule. If you confirm this is the codecov base-pointer issue (and want to investigate line 426), I'll re-approve.
codecov/patch failed — analysis in follow-up COMMENT review. Looks like a stale-base artifact, but per CLAUDE.md dismissing pending your confirmation.
|
Confirming both:
Local
|
worktrunk-bot
left a comment
There was a problem hiding this comment.
Thanks for verifying both — the stale codecov parent (bfb117a6, pre-#2704) and the cargo-llvm-cov mismatched-data on 412/415/426/437 match what I'd be looking for, and the manual trace of the orphan path (%(ahead-behind:main_sha) returns 1 N, rev-list --count returns N, line 426 fires producing (0, 0)) is the right way to confirm the assert in prime_upstream_normalizes_orphan_to_zero exercises that arm. Re-approving.
Release v0.50.0. Highlights: - Experimental Azure DevOps support (#1256, thanks @mikeyroush; fixes #1144 from @dlecan) — `wt switch pr:<N>`, `wt list --full`, and `wt config show --full` recognize Azure DevOps via the `az` CLI. - Experimental Gitea CI-status detection (#2702) on top of the Gitea `pr:` shortcut (#1320, thanks @SjB). - Hooks now resolve `.config/wt.toml` from the worktree they act on — the primary-worktree fallback is gone, and `post-remove` reads the removed worktree's config (snapshotted before removal). Approval prompts collect hook commands from the same worktree. Breaking change for setups that relied on the primary-worktree fallback; the changelog entry has the recovery action. (#2690, #2703, #2714, #2717, #2701, #2708, #2727, #2736, #2748) - The `wt switch` picker's `alt-r` removal no longer runs unapproved project hooks (#2746) — the picker's removal path is now routed through `handle_remove_output` and consults the existing approval state read-only. - `wt config alias show` with no name lists every alias's full definition (#2684, #2691); `wt --help` switches to a compact aliases pointer (#2688). - `wt list --branches` warm-run perf: SHA-keyed cache for `main↕` and `Remote⇅` ahead/behind counts; shared push-remote URL and local-branch scan (#2704, #2718, #2673). - Claude Code plugin ships the `wt-switch-create` skill (#2737, thanks @onetom for #2631). See `CHANGELOG.md` for the full list (8 Improved, 5 Fixed, 5 Internal). semver-checks reports breaking library-API changes (new enum variants without `#[non_exhaustive]`, removed `Branch::github_push_url`, new trait method on `RemoteRefProvider`), which mandates at minimum a minor bump pre-1.0.
Summary
main↕cold-start primer from perf(list): cache ahead/behind counts SHA-keyed; skip the for-each-ref walk on warm runs #2704 for theRemote⇅column.Repository::prime_upstream_ahead_behind_cacheruns onefor-each-ref %(ahead-behind:UPSTREAM_SHA)walk per unique upstream SHA (scoped to that upstream's branches) and bulk-writes theahead-behind/cache. Per-rowUpstreamTask::computereads the cache viaahead_behind_by_sha.rayon::scopeso it reads the snapshot's already-scanned local/remote inventories — no extrafor-each-ref refs/remotes/fork. Candidates scoped to branches that actually render anUpstreamTaskrow (worktree-attached when!show_branches). Primer honorslist.task-timeout-msviaset_command_timeout.%(ahead-behind:UPSTREAM_SHA)(not:refname) so git counts against the SHA the cache will be keyed by; cache key uses the%(objectname)git reports in the same walk; writes flow throughput_ahead_behind_bulk(onesweep_lruat end); orphan branches normalize to(0, 0)via per-upstream memoizedrev-list --count.Known limitation
When every branch tracks its own remote (distinct upstream SHA per branch), every group has
refs.len() == 1and the primer skips all of them — those fall through to the per-row parallel path. A%(upstream:track)walk could batch them, but git computes that atom against the upstream's current value at walk time, which we can't pin to the SHA the cache will be keyed by; the resulting race would break the cache invariantcompute_ahead_behindestablishes on a miss. Documented in the primer's docstring.Before/after on a 10-branch shared-upstream fixture
Cold
wt list --branchestrace (RUST_LOG=worktrunk=debug):for-each-ref --format=%(refname) %(objectname) %(ahead-behind:<main_sha>) refs/heads/— snapshot'smain↕walk (unscoped)for-each-ref --format=%(refname) %(objectname) %(ahead-behind:<feat-base_sha>) refs/heads/feat-base refs/heads/work1 ... refs/heads/work10— primer's scoped Remote⇅ walkWarm run:
grep ahead-behind:returns 0 — both walks skipped, cache hits everywhere.Test plan
ref_snapshot.rsmirror thecapture_ahead_behindpatterns (cold→warm tampered-cache survival, no-upstream /[gone]skips, orphan normalization, sub-threshold skip, two-upstream-group routing, equal-branch(0,0), local-upstreambranch.X.remote = .resolution)cargo run -- hook pre-merge --yes— 3664 tests pass/review-codexiterated to convergence on cache correctness, candidate scoping, redundant remote-scan, and timeout coverage