Repository navigation
perf: defer directory and adoption key derivation - #181760
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
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. |
76d468c to
73a1231
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73a12311f8
ℹ️ 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".
Only resolve event paths for subtree filtering, and parse Codex session keys after metadata eligibility. Preserve shared watcher recovery, revision ownership, and live binding checks.
73a1231 to
51542d4
Compare
* perf: defer directory and adoption key derivation Only resolve event paths for subtree filtering, and parse Codex session keys after metadata eligibility. Preserve shared watcher recovery, revision ownership, and live binding checks. * test(perf): seed complete supervision binding fixtures * fix(perf): declare standalone watch adapter contract * fix(perf): drain buffered directory GC observations
What Problem This Solves
Directory notifications and Codex session listings allocate temporary data for facts their callers do not need.
User Impact
The same notifications and adopted-session results require less allocation and CPU work. No configuration, migration, or user action is required.
Why This Change Was Made
Direct-root directory subscribers consume the filename, so derive an absolute changed path only when subtree filtering or rename readmission needs it. Keep the native-watch lifecycle, containment checks, listener snapshots, and recovery behavior.
Codex adoption now rejects ineligible metadata before parsing session keys and fills the candidate array directly instead of using a generator and spread. The existing revision cache remains the owner of prepared candidates, while binding authority is checked live on every list. The SDK snapshot does not carry a reusable parsed suffix; expanding it or materializing presentation rows would add work and another contract.
Runtime production code is 21 added / 23 removed, net −2 lines. The larger diff is reproducible proof tooling: 635 benchmark-script lines and 61 README lines, plus seven assertions in existing tests. Including that required tooling and README, the non-test diff is +694 lines; the runtime simplification itself adds no cache, API, or dependency.
Evidence
On the same Linux host and Node 26.12.1, paired baseline/candidate processes used an exclusive quiet slot, interleaved 16-CPU sets, and swapped placement. Preparation was sequential on separate preparation CPUs; the unchanged production guard, per-process memory limits, and CPU/I/O weights applied throughout. Baseline owner source was
e8faae4b893f59bf735fedcdae0ef488f502d3d8; both sides used the same remaining source and dependencies. Subsequent rebases did not change either measured runtime owner.Adoption allocation falls by about 954 KB per fresh-revision list. At the representative paced workload of 6.3 lists/minute, that projects to about 6.0 MB/minute less allocation, not a measurement of whole-Gateway savings. The directory result saves about 891 B/event; no production event-count rate was collected, so no aggregate watcher saving is claimed.
The paced event-loop result is mixed and is not claimed as a tail-latency win. Pair 1 increased 1.182719 → 1.779711 ms (+0.596992 ms / +50.48%, n=107,246/107,183); the swapped pair changed 1.059839 → 1.058815 ms (−0.001024 ms / −0.097%, n=107,989/108,035). Following v5.2, the required third pair was unchanged at 1.059839 ms (n=108,233/108,283). The mean absolute delta is +0.198656 ms, or +18.05% of the mean baseline; the mean relative paired delta is +16.79%. This stays below the 20% gate and is not adverse in both swapped pairs. The GC-only sub-millisecond exception was not applied to this metric. Paced CPU, total GC, and promotion all fell in every pair (paired means −26.9%, −29.9%, −35.8%). List-latency tails at this rate have only 12 samples per side and are context.
Directory event-loop p99 had opposite signs in the first two pairs (−0.262144 ms / −19.68%; +0.001024 ms / +0.051%, each n=5,999 per side). The required third pair was −0.106496 ms / −5.33%; its absolute mean across three pairs was −0.122539 ms. A fourth pair, validating the completed GC reporter, was unchanged. No directory regression gate fires. Adoption stress event-loop p99 fell 29.52% and 31.96% (n=5,999 per side); total GC fell 62.6% and promoted bytes 47.4% on paired means.
The acceptance rule was written before measurements: reject a gating metric at mean ≥20% adverse, or ≥10% adverse in both swapped pairs. p95 requires 200 samples per side, p99 1,000; major-GC tails are context below 50 collections. Opposite signs or >5× baseline variation require a third pair and an absolute-mean decision. Per-collection GC pause shifts below 1 ms are context, as are fuller pauses when collection count falls ≥20% without more total GC. Every candidate maximum must remain at or below max(50 ms, twice its paired baseline maximum). Total GC per work, promotion, and eligible event-loop p99 still gate.
The canonical synthetic fixture contains 5,000 stored sessions, 6,000 retained runs, 200 approvals, 100 cron jobs, and 12 projects/worktrees; transcript payload is zero. The measured catalog uses 4,984 stored rows and 16 valid synthetic adoptions, with a new snapshot revision per list. Every result matches the complete expected ordered map. Raw input hashes include distinct sandbox paths; all 5,000 persisted rows in the first pair matched exactly after normalizing only the isolated state-directory prefix (no omitted fields). Output hashes match across sides.
Focused proof: 34 tests passed, with two platform-gated macOS watch-host cases skipped; both added work-count assertions were red on baseline (two path resolutions for two direct events; 3,001 key parses for one eligible adoption) and green on the change (zero and one). The unchanged-revision case still performs no reparse. Core typecheck, changed-file formatting and lint, export-name collision guard, and 22 source-closure tests passed. Independent review was clean at P0–P2. GitHub Codex review also completed on
51542d412aacafea3f4a9acc26980c9ba10b2be8with no remaining findings; its earlier GC-reporter finding is fixed and resolved.Final-head CI passed on
51542d412aacafea3f4a9acc26980c9ba10b2be8: run 39992207596. All required checks passed, including the aggregate CI gate; no CI reruns or inherited-failure exceptions were needed.CI found and prompted correction of a benchmark-only
fs.watchreceiver type declaration. Review also found that the directory reporter needed to drain buffered GC observations. The reproducer returned zero delivered entries plus one buffered entry after a single event-loop turn; the reporter now drains through its measurement-window filter. All ten earlier directory captures matched the independent raw trace counts, and the corrected reporter's fourth pair matched 238/34 collections exactly. Failed dependency setup attempts never entered measurement and are excluded; the same surviving dependency tree was relinked without reinstalling or changing versions. No captured pair was interrupted by the shared guard.Reproduce with the committed
scripts/perf/owned-directory-events-measure.tsandscripts/perf/adoption-candidates-measure.tscommands inscripts/perf/README.md: use--operations 6000, a common--start-at, separate state directories and logs, and--owner <baseline-sibling.ts>for baseline. Add--team-shapefor adoption,--allocationsonly for separate allocation passes, and--operations 12 --yield-ms 9500for the paced adoption case.These are source-owner measurements: real directory subscriptions with deterministic native-callback replay, and the real adoption/binding decoder with an in-memory binding adapter. They do not measure filesystem throughput, full Gateway RPC latency, SQLite latency during capture, or native App Server latency. The post-deploy signal is disappearance of direct-root
resolve ← owned-directory-observationallocation and key parsing restricted to eligible adoptions on changed revisions; no live deployment or post-deploy result is claimed.All paired measurements, sample counts, and maximum GC pauses
All arrows are baseline → candidate. CPU/GC values cover equal operation counts; directory pairs each contain 390,000 events, adoption stress pairs 6,000 lists. Paced pairs contain 12 lists at a 9.5-second interval. Times are milliseconds.
Unprofiled stress pairs
Per-collection GC tails are context under the stated count/pause rules. The maximum column includes every observed GC kind.
Unprofiled paced pairs
Per-collection GC tails are context under the stated count/pause rules. The maximum column includes every observed GC kind.
Separate allocation profiles
Allocation-profile timing/GC context (the profiler is enabled; timing decisions above use unprofiled pairs):
Key-parser allocation is sampled stack attribution, affected by inlining; the work-count assertions establish parse counts independently. Profiled timing remains separate from the unprofiled decision runs.