Skip to content

perf(agents): reduce descendant-count allocation - #184566

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-subagent-descendant-run-count-20261026
Oct 26, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-subagent-descendant-run-count-20261026

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Repeated session-list presentation allocates temporary iterator records and options while counting already-indexed subagent descendants. Each query window counts every requester candidate; overlapping display/filter consumers reuse that window's existing count map, but fresh windows repeat the allocations.

User Impact

Lower allocation and CPU in descendant-count reads, with unchanged active/pending counts, traversal order, generation selection, live-owner checks, and requester-settlement behavior. No protocol, configuration, schema, or recovery changes.

Why This Change Was Made

Read the frozen descendant-key array by index, carry its existing lookup result into the counter, and share the fixed active-only options. Keep one counting implementation and the existing per-window memoization. No incremental counters or new invalidation responsibility.

Related: #184152, closed unmerged as an experiment because its final hardware-dependent proof was unavailable. This is a narrow descendant-only change, excluding its controller-selection changes and settled-tree fast path. The current-main residual was reproduced; this is not an already-fixed claim.

Runtime delta: +7 LOC in one module. The small growth expresses direct indexed traversal and shared fixed options while preserving the common settlement-filter path; no new cache or lifecycle machinery. The benchmark is separate from runtime code. No shared perf README edits.

Evidence

Acceptance declared in the committed probe before comparison: lower sampled bytes/query, identical fixed checksums, and no consistent CPU regression. Synthetic in-memory owner workload: 10,000 retained runs, 2,000 requester roots, five children per root, 100 unended children. Each arm runs 3,000 fresh query windows / 6,000,000 count calls. Five alternating AB/BA pairs per mode; timing is untraced, collected-object allocation is a separate pass. Fixture construction and warmup are excluded; all bytes in the measured region are counted, including caller/window overhead. No frame-name attribution or allocation subtraction.

Base owner: 05a0dd8ee67f1896886198f81d25188f0304d18b, verified byte-identical to the measured baseline module. Same dependency tree and benchmark on both arms; baseline materialized with imports resolved to the same unchanged dependencies. Local single-process runs each take less than 30 seconds.

Metric (five-arm mean) Base Candidate Change Better pairs
Sampled allocation / count query 427.07 B 139.97 B −67.2% 5/5
Main-thread CPU / count query (untraced) 0.2540 µs 0.2130 µs −16.1% 5/5
Array iterators / active + pending count (regression) 2 0 −2 —

Allocation ranges: base 425.81–427.94 B/query, candidate 138.53–141.73. CPU ranges: base 0.2405–0.2783 µs/query, candidate 0.1952–0.2345. Each mode measures 30 million queries per arm in total. Host one-minute load: 42.95–45.99 during timing and 38.95–43.49 during allocation; recorded per arm in JSON.

Reproduce on each revision:

node --expose-gc --import ./scripts/tsx.mjs scripts/perf/subagent-descendant-count-measure.ts timing
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/subagent-descendant-count-measure.ts allocation

The new work-count regression fails on main with expected 2 to be 0; all other tests in that file pass. The iterator instrumentation is restored synchronously in finally. The focused query, read-context, and liveness-owner files pass 32 tests, including status/generation/move/removal churn, cycles, stale-time boundaries, and released-owner reads. Export collision guard and both closure guard files pass (26 tests). Focused run wall time: 95.57 s across two shards; query file execution is under one second. Closure guards: 62.24 s. Final query regression rerun: 19/19 tests, 46.95 s wall time. Changed-file formatting and lint pass. The standalone probe is registered as an exact Knip command entry; the repository-wide unused-file scan was not run under the local-compute restriction. Exact-head CI run 40315045711 completed successfully on 68dd8daa0247ec9e238ee73204a3e93416720df9, including production/test typechecks, lint, affected tests, architecture guards, and baseline checks. GitHub Codex review also completed on that head with no findings.

Review: independent subagent review (autoreview route unavailable). The Codex helper refused the requested route because it does not match operator configuration; configuration was left unchanged. The fresh independent P0–P2 review is clean with no actionable findings.

Scope of evidence: owner microbenchmark only. This removes temporary work while retaining ownership and liveness semantics; no multi-pair Gateway stress campaign was run. Whole-Gateway CPU, GC, RSS/heap, server-handler and client latency improvements are not claimed. No production load or runtime changes.

@clawsweeper

clawsweeper Bot commented Oct 26, 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.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: S labels Oct 26, 2026
@steipete
steipete marked this pull request as ready for review October 26, 2026 11:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 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-26T11:28:04.995166Z 68dd8da Draft marked ready
ℹ️ 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@steipete
steipete merged commit 4293b68 into main Oct 26, 2026
213 of 216 checks passed
@steipete
steipete deleted the steipete/perf-subagent-descendant-run-count-20261026 branch October 26, 2026 11:46
steipete added a commit that referenced this pull request Oct 26, 2026
…184698)

Row presentation resolved each child session's controller by iterating that child's runs through the registry (iterator, closure and owner tuples per call), and countActiveDescendantRuns walked descendant runs on every list. On Team these were among the top selection-side allocation families (getSubagentRunsForChildSession, resolveSessionChildController, countDescendantRuns).

The incremental registry run index (#183531) now keeps the latest matching controller per child session current through its existing update path, so presentation reads it directly. Descendant reads iterate the prepared buckets without per-call allocation, rebased on #184566, which already passes prepared descendants into countDescendantRuns. Results are identical; property tests cover status transitions, replacement runs and agent mismatches.

Evidence, 11 interleaved pairs on AWS c7i.4xlarge: owner-resolution allocation 8.551 -> 1.645 MB/pass (-80.8%, 11/11), descendant reads 292.1 -> 72.8 KB (-75.1%, 11/11), whole-list allocation 4.446 -> 4.299 MB (-3.3%, 10/11); CPU inconclusive. Team-shape harness (20 measured minutes): handler mean 16.67 -> 16.88 ms, main CPU 12.49% -> 12.55%, GC flat, 40/40 turns, zero RPC errors; no regression under the rule. 174 tests pass. Runtime +45 LOC.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…penclaw#184698)

Row presentation resolved each child session's controller by iterating that child's runs through the registry (iterator, closure and owner tuples per call), and countActiveDescendantRuns walked descendant runs on every list. On Team these were among the top selection-side allocation families (getSubagentRunsForChildSession, resolveSessionChildController, countDescendantRuns).

The incremental registry run index (openclaw#183531) now keeps the latest matching controller per child session current through its existing update path, so presentation reads it directly. Descendant reads iterate the prepared buckets without per-call allocation, rebased on openclaw#184566, which already passes prepared descendants into countDescendantRuns. Results are identical; property tests cover status transitions, replacement runs and agent mismatches.

Evidence, 11 interleaved pairs on AWS c7i.4xlarge: owner-resolution allocation 8.551 -> 1.645 MB/pass (-80.8%, 11/11), descendant reads 292.1 -> 72.8 KB (-75.1%, 11/11), whole-list allocation 4.446 -> 4.299 MB (-3.3%, 10/11); CPU inconclusive. Team-shape harness (20 measured minutes): handler mean 16.67 -> 16.88 ms, main CPU 12.49% -> 12.55%, GC flat, 40/40 turns, zero RPC errors; no regression under the rule. 174 tests pass. Runtime +45 LOC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant