Skip to content

perf(list): skip the PR/MR lookup for branches never pushed - #4289

Merged
max-sixty merged 3 commits into
mainfrom
ci-skip-unpushed
Sep 27, 2026
Merged

max-sixty merged 3 commits into
mainfrom
ci-skip-unpushed

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

A forge opens a PR/MR only from a branch it hosts, so a local branch that no remote has under its name can't head one. wt list --full, the statusline and the picker still asked the forge about every such branch whenever the CI cache (30–60s) had expired. On a repo with 239 local branches, of which 19 exist on origin, that was 249 gh calls at ~450ms and ~65ms of CPU each, about 15 CPU-seconds per run.

detect_ci now skips the PR/MR lookup for a local branch that was never pushed: no remote has a branch by that name, and the branch's push remote (or the primary remote, when none is set) has a fetch refspec that would have recorded it under refs/remotes/. git push updates the remote-tracking ref only where the fetch refspecs map the branch. So a --single-branch or --depth clone, which maps only the cloned branch, still asks the forge about every other branch. A URL push remote (gh pr checkout of a fork's PR) has no refspecs and is still asked about too. Both checks read the ref inventory and config map already cached for the command. The branch-workflow fallback is unchanged, and the rule applies to every forge.

The push remote now comes from the existing local-branch scan (%(push:remotename), no measurable cost) instead of one for-each-ref per branch. Branch::push_remote_url forks nothing after the first scan, and the per-branch cache that existed only to avoid that fork is deleted.

Measured with wt list --full on that repo, CI cache cleared, 5 runs each at load average ~30:

main this branch
gh calls 249 25
last CI result (median) 9.25s 5.2s
total wall (median) 12.0s 9.6s

Under that load the local git work was the bottleneck, and the 25 calls started only at 2.3–5s. On a quiet machine the CI tail should be close to one round trip; that's an estimate, not a measurement.

The trade-off: a PR opened from a branch pushed by another clone, and not yet fetched here, shows no PR until the next fetch. The help text's blank-CI row now reads "Branch never pushed", replacing "No upstream", which was never exactly when the cell goes blank.

test_pr_lookup_skips_branches_on_no_remote checks the gh call log for four cases: pushed, URL push remote, a push remote set up like a --single-branch clone, and never pushed. Dropping either the remote check or the refspec check fails it. refspecs_track_ref_follows_the_fetch_mapping covers the refspec matching, including negative refspecs.

This was written by Claude Code on behalf of max-sixty

🤖 Generated with Claude Code

max-sixty and others added 2 commits September 26, 2026 19:13
A forge opens a PR/MR only from a branch it hosts, so a local branch that no
remote has under its name can't head one. `wt list --full` still asked the
forge about every such branch: on a repo with 239 local branches, of which
19 exist on `origin`, that was 239 `gh pr list` calls at ~450ms and ~65ms of
CPU each, about 15 CPU-seconds whenever the CI cache had expired.

`detect_ci` now skips the PR/MR lookup for a local branch unless some remote
has that name, or the branch pushes to a URL (`gh pr checkout` of a fork's
PR sets that, and git keeps no `refs/remotes/` copy of a URL remote). Both
checks read inventories already cached for the command. The branch-workflow
fallback is unchanged.

The push remote now comes from the local-branch scan (`%(push:remotename)`)
instead of one `for-each-ref` per branch, so `push_remote_url` forks nothing
after the first scan and the per-branch cache it needed is gone.

On that repo, with the CI cache cleared: 249 forge calls become 25.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In single-branch and shallow clones, a pushed branch now never shows its PR. The details are inline.

Comment thread src/commands/list/ci_status/platform.rs Resolved
A missing `refs/remotes/<remote>/<branch>` shows a branch was never pushed
only where a push would have recorded one. `git push` updates the
remote-tracking ref only where the remote's fetch refspecs map the branch,
so in a `--single-branch` or `--depth` clone, which maps only the cloned
branch, a pushed branch with an open PR looked unpushed and lost its CI.

The skip now also requires the push remote (or the primary remote, when none
is set) to have a fetch refspec mapping the branch into `refs/remotes/`. A URL
push remote has no refspecs, so that case falls out of the same rule and
`Branch::pushes_to_url` goes away. The blank-CI help row now says "never
pushed".

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty max-sixty changed the title perf(list): skip the PR/MR lookup for branches on no remote perf(list): skip the PR/MR lookup for branches never pushed Sep 27, 2026
@max-sixty
max-sixty merged commit 7294e79 into main Sep 27, 2026
40 checks passed
@max-sixty
max-sixty deleted the ci-skip-unpushed branch September 27, 2026 04:09
max-sixty pushed a commit that referenced this pull request Sep 27, 2026
Four comments no longer matched the code after yesterday's `wt list`
perf work. This PR changes only comments, no behavior.

- **`src/commands/list/collect/mod.rs`**: the stale-default-branch note
said the picker skips the local branch inventory (#5) when branches are
hidden, so it can fork one `for-each-ref`. Since #4290, the first scan
phase primes `repo.local_branches()` unconditionally. The check reads
the cached inventory, so it never forks.
- **`src/commands/list/ci_status/mod.rs`**: `detect_uncached` said
"PR/MR detection always runs". Since #4289, `platform::detect_ci` skips
the lookup for a branch that was never pushed (`may_head_pr`).
- **`tests/integration_tests/push.rs`**: a test doc named
`finalize_worktree`, which #4286 renamed to `finalize_worktrees`.
- **`src/shell_exec.rs`**: `Cmd::run_concurrently` said at most
`max_concurrent_commands()` children run at once. A background batch
takes a single semaphore permit while other threads hold the rest, so
the cap holds per batch, not per process. The comment now says so.

No test accompanies this, since only comments change.

Co-authored-by: worktrunk-bot <[email protected]>
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