Skip to content

Cut three duplicate git subprocesses per wt list statusline render - #2209

Merged
max-sixty merged 1 commit into
mainfrom
statusline-cache-misses
Apr 14, 2026
Merged

max-sixty merged 1 commit into
mainfrom
statusline-cache-misses

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Three in-process cache misses caused wt list statusline --claude-code to spawn 33 git subprocesses per render, four of which were exact-input duplicates the existing in-memory caches should have caught.

  • git rev-parse --git-common-dir ran twice — once from init_command_log early in main, once from the command handler — because each Repository::at() builds its own RepoCache. Added a process-wide LazyLock<DashMap<PathBuf, PathBuf>> keyed by discovery path. Targeted at the dedupe alone; not sharing the whole Repository, because per-Repository caches like commit_shas["HEAD"] go stale after a git rebase mid-wt merge run (an attempt to do that broke seven merge tests).
  • git rev-parse --show-toplevel × 3 and --git-dir × 2 because WorkingTree::root() / git_dir() cache by raw input path, and statusline reaches them via two paths that resolve to the same worktree but differ in form (cwd from the Claude Code JSON vs path from git worktree list --porcelain). Repository::worktree_at() now canonicalizes its input (with raw fallback when the path doesn't exist yet), so equivalent forms collapse to the same cache entry.
  • git merge-base main <sha> and git merge-base main statusline-cache-misses ran as separate merge_base() cache entries because the key was the literal input pair. merge_base() now resolves both inputs through the cached commit_shas map before keying. New resolve_to_commit_sha helper short-circuits inputs that already look like 40-char hex SHAs, so resolving an already-SHA ref doesn't spawn rev-parse.

Verified with a PATH-shimmed git wrapper recording every subprocess: 33 → 29 git invocations per render on a clean tree (the four duplicates above all collapse). Full test suite passes; only the three pre-existing flaky shell-wrapper PTY tests time out (same on main).

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

- Cache `git rev-parse --git-common-dir` process-wide so multiple
  `Repository::at(same_path)` calls (e.g. `init_command_log` then a
  command handler) share the result.
- Canonicalize the input path inside `Repository::worktree_at()` so
  callers passing equivalent forms (cwd from Claude Code JSON vs path
  from `git worktree list --porcelain`) hit the same `worktree_roots`
  / `git_dirs` cache entries.
- Resolve `merge_base()` inputs through the cached `commit_shas` map
  before keying the cache, so `merge-base("main", "<sha>")` and
  `merge-base("main", "branch")` collapse to one entry. New
  `resolve_to_commit_sha` helper short-circuits 40-char hex inputs so
  resolving an already-SHA ref doesn't spawn `git rev-parse`.

Verified with a PATH-shimmed `git` wrapper: 33 → 29 git subprocesses
per render on a clean tree.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 83f4fe0 into main Apr 14, 2026
21 of 23 checks passed
@max-sixty
max-sixty deleted the statusline-cache-misses branch April 14, 2026 00:47
max-sixty added a commit that referenced this pull request Apr 14, 2026
Documents the `wt-perf cache-check` workflow against a real
`wt list statusline --claude-code` trace as a weekly maintenance
item. Includes the exact `RUST_LOG=debug … | grep wt-trace |
wt-perf cache-check` invocation, a stdin-JSON stub, triage
guidance for distinguishing legitimate distinct calls from real
cache misses (with the merge_base / worktree_at precedents from
PR #2209), and a 29-subprocess clean-tree baseline so future
regressions are visible.

Co-Authored-By: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Apr 14, 2026
Captures the `wt-perf cache-check` workflow as a weekly maintenance task
in the `running-tend` skill, alongside the existing MSRV bump.

The render of `wt list statusline --claude-code` runs on every Claude
Code prompt redraw, so any new in-process cache-miss duplicate there
compounds into measurable fseventsd / IPC load — worth catching weekly
rather than waiting for someone to notice the macOS daemon pegged at
100% CPU.

Includes the exact `RUST_LOG=debug … | grep wt-trace | wt-perf
cache-check` invocation with a stdin-JSON stub, triage guidance for
distinguishing legitimate distinct calls from real cache misses (with
the `merge_base` / `worktree_at` precedents from PR #2209), and a
29-subprocess clean-tree baseline so a jump above ~32 is visible.

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude <[email protected]>
worktrunk-bot added a commit that referenced this pull request Apr 14, 2026
…rename

Two stale references from #2201 (verbose.log → trace.log split) and
#2209 (git-common-dir caching):

- Replace `VERBOSE_LOG` with `TRACE`/`OUTPUT` (the two log sinks that
  replaced it) in the process-level singletons list in `src/git/
  repository/mod.rs`, and add `GIT_COMMON_DIR_CACHE` which was added
  in #2209 but missed in the inventory.
- Rename `test_diagnostic_verbose_log_contains_git_commands` to
  `test_diagnostic_trace_log_contains_git_commands` in `tests/
  integration_tests/diagnostic.rs` — the assertions already target
  the "Trace log" section. Rename local bindings for consistency.

Pure documentation/test-naming cleanup; no behavioral change.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
max-sixty pushed a commit that referenced this pull request Apr 28, 2026
## Summary

Per #2449 maintainer feedback, this PR was originally going to add
skill-authoring guidance to `CLAUDE.md` and apply an audit to existing
skills. The follow-up comment clarified that the *guidance itself*
belongs in tend's repo (where `tend-ci-runner` skills are bundled and
shared across consumers), not in worktrunk's `CLAUDE.md` — so I've
dropped the `CLAUDE.md` commit.

What's left is the audit fix the guidance prompted: the `running-tend`
skill no longer cites the dated `Baseline as of 2026-04-13 ... (see PR
#2209)` reference, just the structural rule (`~29 baseline, jump above
~32 warrants investigation`).

The skill-authoring guidance itself needs to land in max-sixty/tend
(likely under "Skill design: bundled for everyone, overlay for one" in
that repo's CLAUDE.md). The bot doesn't have push access there, so
that's a separate manual change.

---------

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

1 participant