Skip to content

perf(storage): reuse one consumer walk per worktree per inventory - #673

Merged
lastobelus merged 2 commits into
lastcode/mainfrom
lastcode/storage-cleanup-walk-reuse
Nov 9, 2026
Merged

lastobelus merged 2 commits into
lastcode/mainfrom
lastcode/storage-cleanup-walk-reuse

Conversation

@lastobelus

@lastobelus lastobelus commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Storage cleanup's consumer proof re-walked the same trees within one process inventory. On a 356-worktree sweep, WorktreeConsumers.processPathsUseRoot dominated the time. When a captured file can't be resolved by name, which is normal for deleted-but-open files, each query does a full no-follow lstat walk of its target. GeneratedDependencies.removeBatch asked the same fresh inventory about <worktree>/node_modules and then about the whole worktree, walking both. The final guards then repeated this for each fresh capture. Each query also ran realpath on every inventory path, about 11.8k paths of which only about 4k were unique.

Changes:

  • One walk answers nested roots. Walk evidence now records where each matched object or socket was found. In the same TargetObservation (keyed by inventory), a query for a root nested in an already-walked root is answered from that walk. The nested subtree's directory tokens and the root's canonical path are revalidated first. The answer matches a fresh walk: a successful ancestor walk visited every object a nested walk would, on the same device and within the same limits. If no ancestor walk is usable, the root is walked as before.
  • One observation per fresh capture. Dependency and build removal proofs create one observation for each fresh capture and query the worktree before its nested root. Every final proof still captures a fresh inventory and never uses the sweep's observation. Each dependency removal now walks each root at most once per capture, down from up to 7 walks per candidate to 4.
  • realpath deduped within each query. Results are not reused across queries: an existing test requires a path that becomes unresolvable later to fall back to identity proof.
  • Dependency use is still recorded when the broader worktree proof fails.

Proof: new tests count walks per capture in WorktreeConsumers, GeneratedDependencies and GeneratedBuilds. They fail on lastcode/main and pass here. The usage-recording test failed before its fix. Focused suites pass (389 tests); check:changed passes apart from the base-branch LegacyFeaturesSection knip failure being fixed in #671; local Quick CI passed.

Follow-up: F1. Deduping realpath within one query can, in a sub-second race, skip re-resolving a duplicate name that changed between its entries. The reviewer rated it a nit, and I declined it.

Local review: 2 rounds with gpt-6.1-terra (xhigh), approved.

🤖 Generated with Claude Code

@lastobelus
lastobelus marked this pull request as ready for review November 9, 2026 17:03
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T17:59:21.066536Z e86a0b5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 4f182d3628

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

lastobelus and others added 2 commits November 9, 2026 10:55
Dependency and build removal proofs asked the same fresh process inventory
about a worktree and about its node_modules or output root separately, and
each question re-walked its whole target tree. A nested root is now answered
from the worktree walk of the same inventory, after its directory tokens are
revalidated, and repeated inventory paths are resolved once per query.
Removal proofs still capture a fresh inventory and never use the sweep's
observation.

Carry-Group: incubator
Carry-Observation: Removal guards create one target observation per fresh capture and query the worktree before its nested root; realpath results are not reused across queries because a later unresolved path must still fall back to identity proof.

Co-Authored-By: Claude <[email protected]>
Querying the worktree first meant a failed worktree-wide walk skipped both
node_modules use checks, so a consumed install kept an old usage clock.

Carry-Group: incubator

Co-Authored-By: Claude <[email protected]>
@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@lastobelus
lastobelus force-pushed the lastcode/storage-cleanup-walk-reuse branch from 4f182d3 to e86a0b5 Compare November 9, 2026 17:57
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: e86a0b598f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lastobelus

Copy link
Copy Markdown
Owner Author

Closing and reopening only to start a fresh CI run: reruns of run 42669616868 left earlier jobs abandoned, so its Check gate could not pass on this head.

@lastobelus lastobelus closed this Nov 9, 2026
@lastobelus lastobelus reopened this Nov 9, 2026
@lastobelus
lastobelus merged commit 308f36e into lastcode/main Nov 9, 2026
54 of 57 checks passed
@lastobelus
lastobelus deleted the lastcode/storage-cleanup-walk-reuse branch November 9, 2026 18:45
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