Repository navigation
perf(root): construct directory metadata without spread copies - #818
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 3:26 PM ET / 19:26 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherRoot 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]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Root metadata listings construct an intermediate
PathStatand 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 unnamedRoot.statresult. 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 blobd9df0a8f9ad189cef383bfd4ef17e147c8d39cc7. 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.
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):
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
pnpm check: 17,014 passed, 729 platform skips, with build, file-size/boundary lint, documentation and installed-package tail passed. AWS leasecbx_d900fbf76206, runrun_c46726e48371122adcce9a6603606ce6.git diff --checkpassed.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_d900fbf76206was released and its state independently verified asreleased.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.