Repository navigation
perf(prewarm): fold cold-path rev-parses into one fork - #2541
Merged
Merged
Conversation
Adds Repository::prewarm() at the top of main: one merged
`git rev-parse --git-common-dir --is-inside-work-tree --show-toplevel
--git-dir --symbolic-full-name HEAD` fork populates the process-wide
git-discovery caches up front, so init_command_log and
try_alias/project_config_path hit memory instead of each spawning their
own rev-parse.
Consolidates the per-RepoCache `worktree_roots` / `git_dirs` /
`current_branches` maps into process-wide LazyLock<DashMap> statics next
to GIT_COMMON_DIR_CACHE. Per-Repo scoping was only ever a historical
accident — the data is filesystem-keyed and process-invariant, and
making it process-wide is what lets one eager prewarm at startup warm
every later Repository::current() (each builds a fresh RepoCache).
WorkingTree::{root,git_dir,branch} read/write the same statics.
Bench (dispatch/{warm,cold}/{1,100}, 30s measurement):
warm/1 22.4 ms → 18.2 ms −18.5%
warm/100 24.3 ms → 18.2 ms −24.1%
cold/1 22.6 ms → 19.3 ms −17.2%
cold/100 28.9 ms → 20.1 ms −27.2%
wt_version unchanged (clap exits before prewarm runs).
Co-Authored-By: Claude <noreply@anthropic.com>
worktrunk-bot
approved these changes
May 3, 2026
`cargo doc -Dwarnings` (run by `pre-merge project:doc`) refuses to
render links from public items to private ones. The prewarm doc and the
docs on `WorkingTree::{prewarm_info, branch, root, git_dir}` linked to
the new `pub(super)` statics — switch those references to plain
backticks; readers of the public API don't need clickable links to
internal caches.
Co-Authored-By: Claude <noreply@anthropic.com>
7 tasks done
Merged
max-sixty
added a commit
that referenced
this pull request
May 3, 2026
Cuts v0.47.0. Highlights: - **Integration detection fix** across `wt list`, `wt remove`, `wt merge`, `wt step prune` for the local/upstream-diverged case (#2507, #2513, #2515). - **Faster shell-command dispatch** (~10ms per invocation, 1.49× on trivial aliases) via event-driven signal forwarding (#2537, #2538), plus parallel config load (#2543) and merged cold-start prewarm rev-parse (#2541). - **`wt switch <number>` suggests `pr:N` / `mr:N`** instead of just `--create` (#2516). - **Library API breaking changes**: `RefSnapshot` cutover (#2528, #2530) and the `for-each` direct-exec change (#2465). Full list in `CHANGELOG.md`. See `CHANGELOG.md` for the complete entry. > _This was written by Claude Code on behalf of @max-sixty_ --------- Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A plain
wt <alias>invocation used to spawn twogit rev-parseforks before alias dispatch:--git-common-dirfrominit_command_logand theprewarm_infobatch (--is-inside-work-tree --show-toplevel --git-dir --symbolic-full-name HEAD) fromproject_config_path. Visible in[wt-trace]output:This adds
Repository::prewarm()at the top ofmain(after the logger is registered, beforeinit_command_logand alias dispatch). One mergedgit rev-parse --git-common-dir --is-inside-work-tree --show-toplevel --git-dir --symbolic-full-name HEADfork populatesGIT_COMMON_DIR_CACHEand the per-worktree git-discovery maps in one shot. Both downstream callers then hit memory.After the change, the trace shows one rev-parse and pure cache hits afterward:
Cache consolidation
Promoting the maps to process-wide is necessary for the optimization to land: every
Repository::current()builds a freshRepoCache, so writing to per-Repo maps fromprewarmwould warm a Repository nobody used. While doing this,worktree_roots/git_dirs/current_branchesmove out ofRepoCachetoLazyLock<DashMap>statics next toGIT_COMMON_DIR_CACHE. Per-RepoCachescoping was a historical accident — the data is filesystem-keyed and process-invariant, and the same staleness contract carries over (snapshot-at-first-read, no invalidation).WorkingTree::{root,git_dir,branch}andprewarm_infonow read/write those statics directly. The intermediatePREWARM_INFO_CACHEsnapshot type is gone — one cache layer instead of two.Caching spec doc updated to describe both layers (
RepoCacheper-Repository, plus the process-wide git-discovery statics).Bench
benches/alias.rs, stub variants, 30s measurement:dispatch/wt_versionprewarm)dispatch/warm/1dispatch/warm/100dispatch/cold/1dispatch/cold/100All four worktree variants regress to ~18–20 ms median regardless of cold/warm or worktree count.
wt_versionis unchanged because--versionis handled by clap insideparse_clibeforeRepository::prewarm()is called — same code path as before.Edge cases
--show-toplevelerrors but--git-common-dirlands first, so we cache the common dir.WORKTREE_ROOTSstays empty for that path (its membership invariant —contains_key⇔ inside a worktree — must hold), soprewarm_inforeforks once. Net cost: same as the unoptimized baseline. The prewarm doc spells this out.WORKTREE_ROOTSandGIT_DIRSbut leaveCURRENT_BRANCHESto thesymbolic-reffallback inWorkingTree::branch, matching the existingprewarm_infobehaviour.wtfrom a non-repo dir) — merged batch fails entirely, nothing cached.Repository::atlater runs its own rev-parse and surfaces the discovery error normally.Test plan
cargo test --lib --bins(1076 + 607 passing, all 4 prewarm tests pass)pre-commit run --all-files(fmt + clippy + lychee + custom checks)dispatch/{warm,cold}/{1,100}🤖 Generated with Claude Code