Skip to content

perf(plugins): reduce tool binding descriptor allocation - #183549

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-plugin-invocation-async-store-20261025
Oct 25, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-plugin-invocation-async-store-20261025

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Plugin tool factories allocate temporary property descriptors while binding each returned tool, even though reflection has already supplied a fresh descriptor for that property.

User Impact

Lower allocation during tool preparation, with no API or behavior change. The measured owner workload uses about 866 fewer bytes per turn (2.64%); allocation attributed directly to the tool binding file falls 37.52%. CPU and latency means are neutral. No whole-Gateway performance claim is made.

Why This Change Was Made

Adapt the freshly returned property descriptor directly instead of allocating an intermediate descriptor literal and another object to spread it into. Data fields still become writable/configurable host views, accessors remain lazy and admitted, and methods keep their original receiver. Tool view ownership, caches, execution wrappers, registry selection, and revocation checks are unchanged. Async stores and invocation frames are outside this change.

This deletes two temporary descriptor constructions per bound property. Production delta: +13/-14 lines, net −1; no new cache, dependency, export, test-only seam, or config. Existing tests already protect the behavior; an implementation-coupled descriptor-identity test would add no behavioral contract.

Evidence

Base measured: 2f95e977c77d74ba463cdfee9436da1004778fcc, Node v26.12.1 on macOS. Five alternating pairs (AB/BA/AB/BA/AB), then one predeclared extra BA pair because timing deltas had mixed signs. Fixed 40,000 turns per run. Results below use signed absolute paired means; relative changes use the mean baseline. No samples, pauses, or maintenance windows were excluded.

Acceptance: demonstrate eliminated owner allocation with non-growing production code and unchanged execution contracts; reject material regressions under the campaign's v5.6 rules. The slight total-GC rise is +0.000084 ms/turn, far below the +1 ms/operation materiality threshold. Loop p99 rises +0.169 ms, below 1 ms, while binding-owner allocation improves >10%. No maximum GC pause exceeds 50 ms. Promotion is near baseline (−0.68%). No A/A rejection controls were needed because no metric supplies a rejection under those rules. This is a small owner simplification, not a claim that whole-turn allocation improved by 10%.

Focused validation: 4 files, 110 tests passed, 101.64 s wrapper wall time, mostly transform/import preparation:

node scripts/run-vitest.mjs \
  src/plugins/registry.factory-bindings.test.ts \
  src/plugins/registry.tool-schema-diagnostics.test.ts \
  src/plugins/tools.optional.test.ts \
  src/plugins/tool-factory-context.test.ts --maxWorkers=1

Changed-file oxfmt, typed oxlint, and git diff --check passed. No new tests or benchmark script: the committed workload below exercises registered plugin factory → prepare → execute, verifies original results, exact plugin/registry scope across awaits, and matching call/authority counts. The existing focused tests also cover private receivers, frozen definitions, lazy schema getters, retained consumer closure, and async authority revalidation.

Rerun on each source revision with isolated HOME and TMPDIR:

node --expose-gc --import ./scripts/tsx.mjs \
  scripts/perf/plugin-gateway-scope-measure.ts \
  --turns 40000 --calls 1 --yield-ms 0 --output /path/to/run.json

For the separate promotion pass, add --trace-gc-nvp before --import, add --gc-log /path/to/run.log, and redirect stdout/stderr to that log. Traced timing is not used for acceptance.

Limitations: this synthetic owner benchmark uses two alternating plugins and one tool per turn, not a full multi-session Gateway or a live model/channel. Minor/major pause percentiles have insufficient collection counts and are context only. Local host load varied. After deploy, inspect sampled allocation attributed to bind in plugin-tool-execution; the frame/async-store allocation family should be unaffected.

Review: independent subagent review clean through P2 (autoreview route unavailable: requested provider did not match operator config). No operator configuration was changed. This PR is for maintainer review and is not being merged by this lane.

Paired measurements and sample counts
Metric Base mean Candidate mean Absolute delta Relative delta
Total sampled allocation, B/turn 32833.426733 31967.331600 -866.095133 -2.64%
Binding-file sampled self allocation, B/turn 2657.944467 1660.760467 -997.184000 -37.52%
Process CPU, ms/turn 0.062198 0.062122 -0.000076 -0.12%
Total GC, ms/turn 0.002440 0.002524 +0.000084 +3.45%
Promotion, B/turn (separate traced pass) 1720.006040 1708.394440 -11.611600 -0.68%
Turn latency mean, ms 0.038119 0.038061 -0.000058 -0.15%
Turn latency p95, ms 0.096549 0.094743 -0.001806 -1.87%
Turn latency p99, ms 0.184938 0.185278 +0.000340 +0.18%
Event-loop p95, ms 1.534804 1.528148 -0.006656 -0.43%
Event-loop p99, ms 2.984959 3.154260 +0.169301 +5.67%

Six pairs, 40,000 turns per side (240,000 turns/side). Promotion: five separate pairs, 200,000 turns/side. Every latency p95/p99 has 40,000 samples per run. Each turn creates one tool factory result and calls prepareArguments and execute once; two synthetic plugin owners alternate. Heap sampling interval 32,768 B includes objects collected by minor and major GC. Allocation and timing are separate passes; timing is untraced. Native async-entry counts and verified factory/prepare/execute/authority counts were identical across sides.

Pair Base / candidate total B per turn Base / candidate binding B per turn Base / candidate CPU ms per turn Base / candidate promotion B per turn
1 32838.23 / 32046.25 2634.23 / 1661.18 0.056873 / 0.050566 1721.61 / 1671.63
2 32839.71 / 32122.11 2648.31 / 1668.50 0.060222 / 0.058770 1723.24 / 1711.45
3 32970.30 / 31873.62 2686.05 / 1659.53 0.052121 / 0.064160 1703.22 / 1720.06
4 32800.01 / 31569.16 2711.36 / 1641.51 0.078881 / 0.065968 1730.61 / 1709.56
5 32923.25 / 32242.87 2667.89 / 1733.46 0.066895 / 0.071211 1721.35 / 1729.28
6 32629.05 / 31949.99 2599.83 / 1600.39 0.058196 / 0.062059 not repeated
Pair Minor count B/C Minor total ms B/C Major count B/C Major total ms B/C Max GC pause ms B/C Loop samples B/C Loop max ms B/C
1 49 / 48 61.815 / 57.340 1 / 1 29.575 / 43.451 29.575 / 43.451 2520 / 2064 31.130 / 45.056
2 49 / 48 70.940 / 64.160 1 / 1 47.672 / 40.501 47.672 / 40.501 2680 / 2616 49.054 / 42.172
3 49 / 48 58.310 / 67.829 1 / 1 33.283 / 42.671 33.283 / 42.671 2030 / 3329 35.226 / 44.728
4 49 / 48 69.065 / 65.603 2 / 1 48.790 / 36.840 31.457 / 36.840 3866 / 3559 32.997 / 38.666
5 49 / 47 64.811 / 64.018 1 / 1 23.187 / 30.319 23.187 / 30.319 3163 / 3317 49.250 / 32.358
6 50 / 47 62.204 / 63.297 1 / 1 12.392 / 27.409 12.392 / 27.409 2558 / 3100 13.541 / 28.787

Minor/major per-collection p95/p99 are context only: none of these runs reaches 200 collections; major count is also below 50. Their full per-pair values follow (each pair uses the collection counts above).

Pair Minor p95 ms B/C Minor p99 ms B/C Major p95 ms B/C Major p99 ms B/C
1 2.077 / 1.531 2.883 / 2.174 29.575 / 43.451 29.575 / 43.451
2 2.360 / 2.197 3.431 / 2.896 47.672 / 40.501 47.672 / 40.501
3 1.399 / 1.940 1.965 / 5.277 33.283 / 42.671 33.283 / 42.671
4 2.291 / 2.313 3.101 / 2.516 31.457 / 36.840 31.457 / 36.840
5 1.614 / 2.028 2.499 / 2.387 23.187 / 30.319 23.187 / 30.319
6 1.926 / 1.681 3.437 / 1.716 12.392 / 27.409 12.392 / 27.409

Reuse the fresh reflected descriptor instead of constructing two temporary descriptors per bound tool property. Preserve callable/accessor admission, receiver binding, mutable host definitions and lifecycle authority. Six paired owner runs reduce binding-file sampled allocation by 37.52% and total allocation by 2.64%; CPU and latency means are neutral. Existing focused contracts: 110 tests passed.
@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T11:18:57.300005Z 8375f76 PR opened
ℹ️ 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses reflected property descriptors when binding plugin tools instead of constructing replacement descriptors.

Example: The supplied workload prepares one plugin tool and executes it once per turn.

  • Before: Reported sampled allocation averages 32,833 bytes per turn.
  • After: Reported sampled allocation averages 31,967 bytes per turn, with the same execution results.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is minimal and behavior-preserving; performance confidence is bounded by the synthetic owner workload.
Proof confidence 🦐 gold shrimp (3/6) The task identifies this as maintainer-authored, outside the ordinary contributor proof gate; its reported macOS Node workload exercises registered factory preparation and execution in process, with measured allocation reduction but no shipped-entry-point evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Plugin tool preparation creates avoidable short-lived allocations.
Reason: The feature-history owner's narrowly scoped change reduces measured allocation without growing production code or changing the documented contract.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR makes a focused allocation reduction while preserving the existing tool-binding contract; no actionable correctness or security findings were identified.

Priority: P3
Reviewed head: 8375f763041b971dabeec2d6917748aa1e477e67

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied measurements do not exercise a running Gateway through a shipped entry point.
Agent review details

How this fits together

Plugin registration routes tool factory results through an execution-binding adapter that exposes mutable host definitions while retaining original receivers, lazy accessors, and captured lifecycle admission.

flowchart LR
  A[Plugin registration] --> B[Tool factory result]
  B --> C[Execution binding adapter]
  C --> D[Host tool definition]
  D --> E[Preparation and execution]
  E --> F[Existing lifecycle admission]
Loading

Technical review

Best possible solution:

Reuse the fresh descriptor inside the existing binding owner while retaining all receiver, accessor, proxy, and lifecycle behavior.

Do we have a high-confidence way to reproduce the issue?

Current main visibly constructs two replacement descriptor objects per bound property; the supplied owner benchmark measures their allocation cost, but no target code was run during this review.

Is this the best way to solve the issue?

The patch removes the redundant constructions at their existing owner without adding caches, alternate paths, public APIs, or test scaffolding.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0fc39d235aa2.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 656a3fa adds src/plugins/plugin-tool-execution.ts:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 656a3fa8d4c6; files: src/plugins/plugin-tool-execution.ts)

PR surface

Source -1. Total -1 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 13 14 -1
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 13 14 -1

Labels

Label changes:

  • add P3: This is a small internal allocation optimization with no demonstrated user-facing latency regression or broken workflow.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This is a small internal allocation optimization with no demonstrated user-facing latency regression or broken workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • A before-and-after allocation profile from an isolated Gateway tool turn would establish whether the owner reduction remains visible through the shipped path.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 25, 2026, 7:31 AM ET / 11:31 UTC.

@steipete
steipete merged commit ce56a01 into main Oct 25, 2026
131 checks passed
@steipete
steipete deleted the steipete/perf-plugin-invocation-async-store-20261025 branch October 25, 2026 11:33
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…3549)

Reuse the fresh reflected descriptor instead of constructing two temporary descriptors per bound tool property. Preserve callable/accessor admission, receiver binding, mutable host definitions and lifecycle authority. Six paired owner runs reduce binding-file sampled allocation by 37.52% and total allocation by 2.64%; CPU and latency means are neutral. Existing focused contracts: 110 tests passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant