Repository navigation
perf(plugins): reduce tool binding descriptor allocation - #183549
Conversation
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.
|
🦞👀 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 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. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherPlugin 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1. Total -1 across 1 file. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 25, 2026, 7:31 AM ET / 11:31 UTC. |
…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.
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:
Changed-file oxfmt, typed oxlint, and
git diff --checkpassed. 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
HOMEandTMPDIR:For the separate promotion pass, add
--trace-gc-nvpbefore--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
bindinplugin-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
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.
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).