Skip to content

perf: defer directory and adoption key derivation - #181760

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-defensive-rederive-20260919
Oct 23, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-defensive-rederive-20260919

Conversation

@steipete

@steipete steipete commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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.

Source-owner workload Mean baseline allocation Mean candidate allocation Mean paired reduction Unprofiled CPU reduction
Direct-root directory event 1,032.9 B/event 141.6 B/event 86.3% 70.9% across four pairs
Adoption list: 5,000 rows, 16 eligible adoptions 1.234 MB/list 0.279 MB/list 77.3% 70.9% across two pairs

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 51542d412aacafea3f4a9acc26980c9ba10b2be8 with 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.watch receiver 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.ts and scripts/perf/adoption-candidates-measure.ts commands in scripts/perf/README.md: use --operations 6000, a common --start-at, separate state directories and logs, and --owner <baseline-sibling.ts> for baseline. Add --team-shape for adoption, --allocations only for separate allocation passes, and --operations 12 --yield-ms 9500 for 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-observation allocation 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

Flow / pair CPU ms Total GC ms Promoted bytes Event-loop p99 ms
directory 1 307.485 → 58.615 29.947 → 4.456 195,168 → 164,536 1.332 (n=5,999) → 1.070 (n=5,999)
directory 2 261.088 → 75.591 31.223 → 5.706 195,168 → 160,064 2.003 (n=5,999) → 2.004 (n=5,999)
directory 3 244.103 → 85.329 31.762 → 9.149 195,112 → 164,776 1.998 (n=5,999) → 1.891 (n=5,999)
directory 4 255.452 → 85.059 37.743 → 8.423 195,616 → 167,128 2.000 (n=5,999) → 2.000 (n=5,999)
adoption 1 3,965.942 → 1,159.627 199.375 → 81.439 18,672,672 → 9,813,656 1.925 (n=5,999) → 1.357 (n=5,999)
adoption 2 4,023.011 → 1,164.114 235.955 → 80.063 18,651,400 → 9,816,496 2.070 (n=5,999) → 1.408 (n=5,999)
Flow / pair Mean operation/batch ms p95 ms p99 ms
directory 1 0.034 → 0.002 0.045 (n=6,000) → 0.004 (n=6,000) 0.050 (n=6,000) → 0.007 (n=6,000)
directory 2 0.026 → 0.003 0.040 (n=6,000) → 0.005 (n=6,000) 0.066 (n=6,000) → 0.007 (n=6,000)
directory 3 0.024 → 0.003 0.038 (n=6,000) → 0.005 (n=6,000) 0.044 (n=6,000) → 0.009 (n=6,000)
directory 4 0.024 → 0.003 0.039 (n=6,000) → 0.004 (n=6,000) 0.045 (n=6,000) → 0.009 (n=6,000)
adoption 1 0.539 → 0.134 0.579 (n=6,000) → 0.157 (n=6,000) 0.753 (n=6,000) → 0.204 (n=6,000)
adoption 2 0.540 → 0.133 0.623 (n=6,000) → 0.160 (n=6,000) 0.951 (n=6,000) → 0.239 (n=6,000)

Per-collection GC tails are context under the stated count/pause rules. The maximum column includes every observed GC kind.

Flow / pair Minor collections Minor p95 ms Minor p99 ms Major collections / max ms All-GC max ms
directory 1 239 → 34 0.202 (n=239) → 0.194 (n=34) 0.209 (n=239) → 0.200 (n=34) 0 / 0.000 → 0 / 0.000 0.225 → 0.200
directory 2 239 → 34 0.242 (n=239) → 0.309 (n=34) 0.325 (n=239) → 0.361 (n=34) 0 / 0.000 → 0 / 0.000 0.471 → 0.361
directory 3 238 → 34 0.474 (n=238) → 0.529 (n=34) 0.751 (n=238) → 2.536 (n=34) 0 / 0.000 → 0 / 0.000 2.579 → 2.536
directory 4 238 → 34 0.368 (n=238) → 0.670 (n=34) 0.627 (n=238) → 0.717 (n=34) 0 / 0.000 → 0 / 0.000 0.696 → 0.717
adoption 1 740 → 63 0.630 (n=740) → 1.843 (n=63) 0.894 (n=740) → 2.283 (n=63) 1 / 46.230 → 0 / 0.000 46.230 → 2.283
adoption 2 735 → 63 0.801 (n=735) → 1.984 (n=63) 1.048 (n=735) → 2.268 (n=63) 1 / 50.966 → 0 / 0.000 50.966 → 2.268

Unprofiled paced pairs

Flow / pair CPU ms Total GC ms Promoted bytes Event-loop p99 ms
adoption 1 984.841 → 671.384 81.376 → 49.605 203,856 → 143,800 1.183 (n=107,246) → 1.780 (n=107,183)
adoption 2 793.334 → 691.195 66.156 → 52.663 227,672 → 138,800 1.060 (n=107,989) → 1.059 (n=108,035)
adoption 3 949.939 → 607.727 83.069 → 58.018 226,304 → 138,336 1.060 (n=108,233) → 1.060 (n=108,283)
Flow / pair Mean operation/batch ms p95 ms p99 ms
adoption 1 2.180 → 1.360 4.954 (n=12) → 2.367 (n=12) 4.954 (n=12) → 2.367 (n=12)
adoption 2 1.897 → 1.390 2.671 (n=12) → 2.110 (n=12) 2.671 (n=12) → 2.110 (n=12)
adoption 3 2.173 → 1.148 2.901 (n=12) → 2.031 (n=12) 2.901 (n=12) → 2.031 (n=12)

Per-collection GC tails are context under the stated count/pause rules. The maximum column includes every observed GC kind.

Flow / pair Minor collections Minor p95 ms Minor p99 ms Major collections / max ms All-GC max ms
adoption 1 15 → 6 1.557 (n=15) → 1.214 (n=6) 1.557 (n=15) → 1.214 (n=6) 2 / 53.778 → 1 / 44.202 53.778 → 44.202
adoption 2 16 → 6 0.962 (n=16) → 1.098 (n=6) 0.962 (n=16) → 1.098 (n=6) 2 / 40.965 → 1 / 44.915 40.965 → 44.915
adoption 3 16 → 6 1.009 (n=16) → 1.041 (n=6) 1.009 (n=16) → 1.041 (n=6) 2 / 55.234 → 1 / 52.593 55.234 → 52.593

Separate allocation profiles

Flow / pair Total bytes / operation Owner bytes / operation Key-parser bytes / list
directory 1 1,032.878 → 138.989 1,010.410 → 118.484 — → —
directory 2 1,032.894 → 144.164 1,011.754 → 121.259 — → —
adoption 1 1,233,992.632 → 279,244.001 1,212,037.197 → 257,992.039 666,565.223 → 5.480
adoption 2 1,233,050.037 → 279,712.563 1,211,083.453 → 258,187.429 680,748.500 → 27.337

Allocation-profile timing/GC context (the profiler is enabled; timing decisions above use unprofiled pairs):

Flow / pair Total GC ms Promoted bytes Event-loop p99 ms Minor / major collections A → B All-GC max ms
directory 1 27.870 → 5.945 196,016 → 164,872 1.258 (n=5,999) → 1.092 (n=5,999) 243 / 0 → 34 / 0 0.642 → 0.286
directory 2 25.710 → 5.085 196,264 → 160,640 1.247 (n=5,999) → 1.086 (n=5,999) 244 / 0 → 34 / 0 0.306 → 0.240
adoption 1 225.354 → 122.260 19,449,120 → 11,778,632 2.329 (n=5,999) → 1.631 (n=5,999) 501 / 2 → 146 / 1 6.576 → 5.757
adoption 2 154.121 → 109.579 19,527,912 → 13,909,432 2.179 (n=5,999) → 1.633 (n=5,999) 499 / 2 → 144 / 1 6.174 → 12.368

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.

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 23, 2026 16:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T17:08:24.022782Z 51542d4 New commits
ℹ️ 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete
steipete force-pushed the steipete/perf-micro-defensive-rederive-20260919 branch from 76d468c to 73a1231 Compare October 23, 2026 16:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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.
@steipete
steipete force-pushed the steipete/perf-micro-defensive-rederive-20260919 branch from 73a1231 to 51542d4 Compare October 23, 2026 17:05
@steipete
steipete merged commit 9dfbbc9 into main Oct 23, 2026
152 checks passed
@steipete
steipete deleted the steipete/perf-micro-defensive-rederive-20260919 branch October 23, 2026 17:16
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. extensions: codex scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant