Skip to content

perf(root): construct directory metadata without spread copies - #818

Merged
steipete merged 1 commit into
mainfrom
perf/non-watch-hotpaths
Oct 1, 2026
Merged

steipete merged 1 commit into
mainfrom
perf/non-watch-hotpaths

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Root metadata listings construct an intermediate PathStat and copy its enumerable fields into a second named object for every entry. Construct the final object directly, preserving field values, getter evaluation order, property order, numeric/bigint timestamp conversion, and the unnamed Root.stat result. This removes an allocation and property-copy work per entry. All lstat/realpath observations, confinement and identity fences, no-follow behavior, batch boundaries, and error paths remain unchanged.

The change also covers the existing sorted/filesystem directory iterator projection sites. No watch module or test-consolidation files change. The benchmark and Unreleased Performance entry are included.

Measurement

Baseline 8b6c276ba4ff66a0e67985af55e197a96a8caa0b; production candidate blob d9df0a8f9ad189cef383bfd4ef17e147c8d39cc7. Dedicated AWS Linux x64 m7i.4xlarge (16 vCPU), Node 24.19.0, CPU 2 pinned, unchanged native binary. Existing benchmark suite and a synthetic OpenClaw-like workload were CPU-profiled and allocation-sampled before editing production code. The workload combines small JSON/text atomic writes, Root writes/reads, 64-entry metadata listings, and stats. Listing projection was the largest library allocation site: about 9.6% of sampled allocations, plus about 1% in the intermediate metadata projection.

The checked-in harness uses three warmup batches and 24 paired samples per row, interleaving A/B and identical-baseline A/A pairs with alternating forward/reverse order. Each 1,000-entry listing sample averages 30 complete calls. Setup, validation, cleanup, tracing and allocation sampling are outside latency measurements. Ratios are geometric means of paired ratios; intervals are percentile 95% paired bootstraps with 10,000 draws and a fixed seed. Before/after columns are medians of sample averages, not per-call p95.

Workload Before µs After µs Candidate/base ratio (95% CI) A/A ratio (95% CI)
1,000-entry metadata list, native off 2,192.18 1,851.92 0.8369 (0.8118–0.8663) 1.0030 (0.9832–1.0294)
1,000-entry metadata list, native require 2,216.74 1,866.23 0.8340 (0.8086–0.8632) 0.9817 (0.9590–0.9984)
100-entry metadata list, off 221.49 192.25 0.9354 (0.8820–1.0188) 0.9879 (0.9706–1.0015)
100-entry metadata list, require 227.61 196.59 0.9337 (0.8828–1.0092) 0.9964 (0.9739–1.0161)
Sorted walk, 1,000 entries, off 3,247.61 2,967.71 0.9453 (0.8544–1.0517) 1.0326 (0.9786–1.0908)
Sorted walk, 1,000 entries, require 3,326.87 2,951.75 0.9243 (0.8467–1.0172) 1.0059 (0.9384–1.0872)
Sorted entries, 1,000 entries, off 10,576.18 10,431.41 1.0053 (0.9639–1.0430) 1.0087 (0.9848–1.0351)
Sorted entries, 1,000 entries, require 10,529.53 10,415.89 1.0046 (0.9772–1.0327) 1.0125 (0.9761–1.0466)

Only the 1,000-entry metadata listing speedup is claimed. Small rows and stat controls were noisy. One unchanged native-required names-only one-entry control measured 1.1972 (1.0712–1.3532), with A/A 0.9435 (0.8184–1.0705). Names-only listing never invokes the changed projection; this observation is retained as environmental/control variability, not hidden or attributed to the optimization. No macOS/Windows speedup is claimed.

Separate allocation sampling (16 KiB interval, including collected objects) over 302 complete 1,000-entry lists plus identical setup/cleanup estimated 694.33 → 499.56 MB (-28.1%) with native off and 686.24 → 498.02 MB (-27.4%) with native require. These are sampled cumulative allocations, not retained heap/RSS or confidence intervals.

Operation-delimited strace over ten 1,000-entry metadata lists confirms unchanged filesystem observations (baseline → candidate):

Mode statx fstat readlink getdents64
off 10,020 → 10,020 10 → 10 40 → 40 20 → 20
require 10,010 → 10,010 30 → 30 20 → 20 20 → 20

No syscall reduction is claimed; the mechanism is allocation/property-copy removal. Whole-process traces are also retained. The initial operation-trace request timed out at the Crabbox coordinator before dispatch; the retry on the same lease completed (run run_c64a5a0d496370ac49d3123d79995790).

Validation

  • Focused Root entries, directory stream identity, walk and stat tests: 185 passed, 6 platform skips.
  • Dedicated Linux pnpm check: 17,014 passed, 729 platform skips, with build, file-size/boundary lint, documentation and installed-package tail passed. AWS lease cbx_d900fbf76206, run run_c46726e48371122adcce9a6603606ce6.
  • Managed Codex autoreview: scoped-clean through P2. git diff --check passed.
  • The first comparison attempt failed on a missing required symlink policy in the walk fixture before producing a completed report. The corrected harness preflights every row before timing; the complete comparison above is the first valid campaign, with all 24 pairs retained.
  • The shared Mac full check observed a watch timing failure and was stopped after the complete dedicated Linux check passed. Final exact-head cross-platform CI and CodeQL both passed on attempt 1; coverage also passed on attempt 1.

Reproduce with the commands in benchmarks/README.md, keeping each dist beside its matching native/package layout. No release is requested or performed.

AWS lease cbx_d900fbf76206 was released and its state independently verified as released.

Final head 159ab9766be25a1f216ab3188b2da54a14bee14c: all-OS CI, CodeQL, and coverage passed on attempt 1. All checks are successful or intentionally skipped. No retry or admin bypass was used.

@steipete
steipete requested a review from a team as a code owner October 1, 2026 19:20
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 3:26 PM ET / 19:26 UTC.

ClawSweeper review

What this changes

The PR constructs directory-entry metadata directly, removes intermediate spread copies from three listing paths, and adds a comparison benchmark and performance release note.

Merge readiness

✅ Ready for maintainer review

This remains a useful, bounded performance improvement absent from the pinned main branch. No introduced correctness or security defect was found; the supplied measurements support the narrowly stated Linux listing speedup.

Priority: P2
Reviewed head: 159ab9766be25a1f216ab3188b2da54a14bee14c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, compatible optimization with detailed real-filesystem measurements and no actionable defect found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied dedicated AWS Linux benchmark exercises the changed Root metadata projection through complete real-filesystem listings, reports an approximately 16% after-fix improvement in both native modes, and retains unchanged observation counts. The checked-in harness verifies output equality, and the reported candidate blob matches the reviewed production source. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied dedicated AWS Linux benchmark exercises the changed Root metadata projection through complete real-filesystem listings, reports an approximately 16% after-fix improvement in both native modes, and retains unchanged observation counts. The checked-in harness verifies output equality, and the reported candidate blob matches the reviewed production source. No stored-data contract changes.
Evidence reviewed 8 items Pinned introduced change: The complete introduced diff changes four files. Production changes only metadata construction and three projection calls; filesystem operations, error handling, identity fences, and batch boundaries are unchanged.
Metadata compatibility: The helper preserves timestamp conversion, stat getter/method evaluation order, numeric conversion, and returned property order. Root.stat still calls the unnamed overload; public PathStat and DirEntry contracts and package exports do not change.
Real filesystem benchmark: The captured PR body reports complete Root.list comparisons on dedicated AWS Linux x64, Node 24.19.0, with native off and require. Twenty-four paired samples give candidate/base ratios 0.8369 and 0.8340 for 1,000-entry metadata lists; allocation sampling reports 27–28% reductions and operation-delimited traces retain identical filesystem observation counts. The production blob matches the reviewed source: d9df0a8f9ad189cef383bfd4ef17e147c8d39cc7. These are contributor-reported results, not reviewer execution.
Findings None None.
Security None None.

How this fits together

Root directory inspection turns filesystem names and stat observations into advisory metadata for listings and traversal. Confinement and identity checks guard those observations before results reach callers.

flowchart TD
  A[Root inspection request] --> B[Admit selected directory]
  B --> C[Read names and filesystem metadata]
  C --> D[Construct entry metadata directly]
  D --> E[Recheck directory identity]
  E --> F[Return listing or traversal entry]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and benchmark delta production +13/-20; benchmark +49; tests +0 Production shrinks while the added harness supports the stated allocation and listing-time improvement.
Large-list comparison 24 paired samples per row; approximately 16% faster in both native modes The reported gain is bounded to the workload whose confidence intervals exclude parity.

Technical review

Best possible solution:

Use direct metadata construction while preserving the existing advisory output contract and all filesystem safety checks.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a bug reproduction: this is an optimization, with a checked-in real-filesystem comparison harness and supplied before/after Linux measurements.

Is this the best way to solve the issue?

Yes. Directly constructing the existing output shape removes the demonstrated allocation without changing filesystem observations, public APIs, or safety boundaries.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8b6c276ba4ff.

Labels

Label changes:

  • add P2: This is a measured performance improvement to directory inspection with limited scope and no urgent broken workflow.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied dedicated AWS Linux benchmark exercises the changed Root metadata projection through complete real-filesystem listings, reports an approximately 16% after-fix improvement in both native modes, and retains unchanged observation counts. The checked-in harness verifies output equality, and the reported candidate blob matches the reviewed production source. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied dedicated AWS Linux benchmark exercises the changed Root metadata projection through complete real-filesystem listings, reports an approximately 16% after-fix improvement in both native modes, and retains unchanged observation counts. The checked-in harness verifies output equality, and the reported candidate blob matches the reviewed production source. No stored-data contract changes.

Label justifications:

  • P2: This is a measured performance improvement to directory inspection with limited scope and no urgent broken workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied dedicated AWS Linux benchmark exercises the changed Root metadata projection through complete real-filesystem listings, reports an approximately 16% after-fix improvement in both native modes, and retains unchanged observation counts. The checked-in harness verifies output equality, and the reported candidate blob matches the reviewed production source. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied dedicated AWS Linux benchmark exercises the changed Root metadata projection through complete real-filesystem listings, reports an approximately 16% after-fix improvement in both native modes, and retains unchanged observation counts. The checked-in harness verifies output equality, and the reported candidate blob matches the reviewed production source. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The complete introduced diff changes four files. Production changes only metadata construction and three projection calls; filesystem operations, error handling, identity fences, and batch boundaries are unchanged. (src/root-directory-list.ts:58, 159ab9766be2)
  • Metadata compatibility: The helper preserves timestamp conversion, stat getter/method evaluation order, numeric conversion, and returned property order. Root.stat still calls the unnamed overload; public PathStat and DirEntry contracts and package exports do not change. (src/root-path-stat.ts:150, 159ab9766be2)
  • Real filesystem benchmark: The captured PR body reports complete Root.list comparisons on dedicated AWS Linux x64, Node 24.19.0, with native off and require. Twenty-four paired samples give candidate/base ratios 0.8369 and 0.8340 for 1,000-entry metadata lists; allocation sampling reports 27–28% reductions and operation-delimited traces retain identical filesystem observation counts. The production blob matches the reviewed source: d9df0a8f9ad189cef383bfd4ef17e147c8d39cc7. These are contributor-reported results, not reviewer execution. (benchmarks/root-entry-projection.mjs:15, 159ab9766be2)
  • Benchmark safeguards: The harness calls real Root APIs against temporary filesystem fixtures, preflights complete result equality and property order, warms both builds, and alternates candidate comparisons with baseline controls. The body discloses noisy controls and limits its speedup claim to large metadata listings. (benchmarks/root-entry-projection.mjs:23, 159ab9766be2)
  • Existing safety coverage: Existing entries tests cover both ordering modes, literal symlink metadata, bounded observations, replacement rejection across yields, and fresh sorted metadata. Observation tests specify stat/list syscall budgets. Tests were inspected without execution under the read-only review contract. (test/root-entries.test.ts:136, 159ab9766be2)
  • Current main and release status: Pinned main still constructs intermediate metadata and spreads it into named entries. GitHub identifies v0.22.0 as the latest release, published before this PR; this optimization remains pending under Unreleased. No merged replacement was established. (CHANGELOG.md:5, 159ab9766be2)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant