Repository navigation
perf(workspace): avoid copying owned projection mutations - #185256
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
🦞👀 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. What this changesThis PR reuses owner-held workspace mutation payloads for worker dispatch and commit recovery instead of deep-copying them. Example: A local workspace checkpoint contains 100,000 paths.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR removes a redundant allocation that remains on main, with no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherLocal workspace reconciliation supplies checkpoint and journal mutations to the existing worker-backed store, which persists them and publishes acknowledged projection rows. flowchart LR
A[Workspace changes] --> B[Projection reconciliation]
B --> C[Local workspace store]
C --> D[Existing worker transport]
D --> E[SQLite transaction]
E --> F[Committed projection snapshot]
F --> B
Technical reviewBest possible solution: Reuse the projection-owned payload within the existing store while preserving predicate snapshots, live authority checks, and settlement recovery. Do we have a high-confidence way to reproduce the issue? Source confirms the redundant clone on current main; supplied measurements distinguish allocation churn from retention, but this read-only review ran no workload. Is this the best way to solve the issue? The smallest complete change removes the copy at its existing owner, and the standalone workload supports the allocation claim without adding runtime machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7611ff916275. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1, Tests +1, Other +348. Total +348 across 4 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 26, 2026, 8:56 PM ET / October 27, 2026, 00:56 UTC. |
Projection operations own mutation data through settlement. Reuse it for worker dispatch and committed-row recovery while retaining predicate snapshots and live authority checks. Add a reproducible retained-row and allocation workload; this reduces copying without claiming to fix an unproven persistent retainer.
Normalize Buffer-backed journal data to a plain Uint8Array view at commit publication without copying its backing bytes. Preserve the existing worker/database row shape for creation and lost-reply recovery; cover both changed owners in the allocation workload.
59dce8b to
85b5c3a
Compare
…85256) * perf(workspace): avoid copying owned projection mutations Projection operations own mutation data through settlement. Reuse it for worker dispatch and committed-row recovery while retaining predicate snapshots and live authority checks. Add a reproducible retained-row and allocation workload; this reduces copying without claiming to fix an unproven persistent retainer. * fix(workspace): preserve published journal byte views Normalize Buffer-backed journal data to a plain Uint8Array view at commit publication without copying its backing bytes. Preserve the existing worker/database row shape for creation and lost-reply recovery; cover both changed owners in the allocation workload.
What Problem This Solves
Large local sandbox checkpoints deep-copy owner-held mutation payloads before the existing worker transport serializes them, allocating another full checkpoint string and journal buffer on the Gateway thread.
User Impact
Reduces allocation during local workspace reconciliation without changing stored bytes, checkpoint ordering, recovery, or authority checks. This is an allocation improvement, not a demonstrated fix for persistent heap growth: the baseline already releases settled rows in the reproduction.
Why This Change Was Made
Projection operations create their mutation inputs and await settlement before reusing them. Reuse those inputs for dispatch and committed-row recovery. Keep the independent predicate snapshot and all live authority checks. Reconstructed rows preserve the worker/database's plain Uint8Array journal shape through a zero-copy view of Buffer inputs.
Runtime source delta: +8 lines. The growth preserves the existing byte-view shape contract that structuredClone previously supplied implicitly; the full mutation copy is removed. Benchmark +355 lines, Knip entry +1 line, existing test +4 net lines. Usage lives in the script header; the shared performance README is unchanged.
Evidence
Two counterbalanced untraced pairs, each arm performing 1,000 updates with a synthetic 100,000-path checkpoint; allocation sampled in separate passes. Final comparisons pin both the store and publication modules.
CPU improved in both pairs: 1.535776→1.458085 s and 1.320573→1.301429 s. GC totals were 124.415→149.126 ms and 97.519→90.497 ms, with mixed signs; the mean absolute rise is 0.008845 ms/update, below the +1 ms/operation absolute gate. Write-wall mean was 8.126→8.196 ms/update (+0.86%), also with mixed signs, so wall timing is context. Host load per arm: baseline 17.10→16.16 and 14.79→13.88; candidate 15.20→14.86 and 14.55→15.29. Forced-GC retention samples are outside measured write windows. These are store-owner measurements, not whole-Gateway results.
All arms release all 1,000 observed rows after settlement, enforced by the workload assertion. Old space remains flat around 57.5 MB while an active store retains only its current row. No growing row history was reproduced.
Real 100,000-file Git checkout, ten rounds of 1,000 guest edits: all edits reached the canonical checkout on both versions, with zero settled rows retained. Old space from cycle 1→10: baseline 92.379→92.325 MB, candidate 92.392→92.329 MB. Heap: baseline 100.695→101.937 MB, candidate 100.712→101.963 MB. Matching trends do not reproduce persistent workspace retention.
Full-reconciliation timing is context only: baseline/candidate main-thread CPU 2.015/2.123 s, wall 160.921/174.057 s, natural GC 30.490/36.050 ms (33/32 collections; max 4.635/12.135 ms). These single runs had host loads 23.55→25.32 and 23.66→24.92, and the baseline preceded an unrelated-main rebase, so no full-flow speedup is claimed. An additional baseline compression-branch probe used a 1,000,000-path inventory (34.120 MiB, above the 32 MiB threshold): across 20 writes old space stayed 154.611→154.545 MB and all observed rows were released.
Proof and Limits
service.retire-snapshot.test.ts: removing structuredClone also removed Buffer→Uint8Array normalization. Reproduced locally, repaired at committed-row publication with a zero-copy byte view, then 37 focused tests passed (store 18; retire-snapshot 19). This failure was ours, not inherited.Reproduce with
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/local-workspace-retention.ts --iterations 1000 --files 100000; add--allocationfor a separate sampled-allocation pass, or--reconcile --iterations 10 --files 100000 --edits 1000for real filesystem reconciliation.--source-dirreplaces both store and publication modules with captured baseline source; other dependencies remain identical within each comparison. CPU is main-thread CPU; worker/Git CPU is not included.