Skip to content

perf(plugins): avoid redundant schema hook invocation scopes - #173448

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-plugin-invocation-scope-20260919
Oct 15, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-plugin-invocation-scope-20260919

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Chat turns allocate avoidable plugin-scope objects while preparing provider tool schemas.

User Impact

Lower allocation in provider tool preparation, with the same schemas, execution behavior, and lifecycle checks. No configuration changes or migration are needed. The measurements below do not establish a whole-turn latency improvement.

Why This Change Was Made

Provider tool-schema preparation invokes the managed function's .call wrapper, causing nested plugin scope entry and repeated executable result binding. Ordinary tool descriptor copying also opens a scope for each tool even though no plugin code runs there.

Invoke the managed schema hook with Reflect.apply, preserving its receiver and lifecycle admission without traversing managed Function.prototype.call. Copy descriptors directly after the existing prototype-chain check. Proxy-backed tools, lazy accessors, and execution/preparation callbacks retain their admitted paths. Production LOC delta: -1; test delta: +38.

No normalization-result cache: hooks receive the current model, configuration, workspace, and run-bound tools, so provider/registry revision alone is not a valid reuse key. No public API, schema, or stored-format changes.

Evidence

Measurement

Source-mode development Gateway, Node 26.11.1, synthetic 5,000-session/6,000-run state with populated transcripts; identical pristine offline fixture for both processes, fixed 90-second post-ready settle. Twenty completed chat turns per side, each with exactly one read-tool call/result and the full expected final assistant text. Baseline 6401ea6c395e; candidate 07086c7d2067.

Main-isolate allocation / turn Before After Change
Targeted schema-normalization scope stack, mean 1.2664 MiB 0.01895 MiB -98.5%
Entire plugin invocation owner, mean 4.466 MiB 3.105 MiB -30.5%
Whole turn, median 113.730 MiB 112.150 MiB -1.4%
Whole turn, raw mean 113.924 MiB 116.858 MiB +2.6%

The raw after mean includes a 179.915 MiB first-round outlier overlapping startup handler prewarm, plugin status, catalog, and schema work absent from the baseline capture. It is retained, not filtered out. These results support the targeted allocation reduction; they do not establish a whole-turn mean or latency improvement. The single separate CPU-only turn was 320.678 → 323.717 ms (+0.95%, neutral at this sampling depth). Latency p50 was 697.446 → 732.412 ms on the contended host. Allocation excludes workers/external buffers and includes the event-drain window.

The benchmark initially failed before measurement because its mock port collided with another isolated lane; the mock also assumed every request had JSON. The rerun used a free port pair and explicit mock request handling. Both completed captures passed all turn validation checks. No production Gateway was used.

Validation

  • node scripts/run-vitest.mjs src/plugins/registry.factory-bindings.test.ts src/plugins/provider-runtime.test.ts src/agents/runtime-plan/tools.test.ts --maxWorkers=1: 98 tests passed, 3 files, 65.16 seconds wall time. Baseline factory-binding file: 12 passed, 53.71 seconds including initial compilation. The new behavior-preservation test also passes on the baseline.
  • Coverage preserves schema/result identity, receiver and plugin scope, detached execution, consumer isolation, Proxy behavior, quarantine, and rejection after retirement.
  • Changed-file formatting, core-config type-aware lint, and git diff --check passed. Lint used --tsconfig config/tsconfig/oxlint.core.json --threads=1 on only the 3 changed files; an initial root-config invocation was stopped when it selected broad package preparation.
  • Independent subagent review (autoreview route unavailable): no actionable P0–P2 findings. The review helper refused the requested provider route because it did not match the operator configuration; configuration was left unchanged.
  • Broad validation is delegated to PR CI. No Testbox/Crabbox lease allocated, per the lane validation rule.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review October 15, 2026 20:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-15T20:23:14.966931Z 07086c7 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.

@steipete
steipete merged commit 656a3fa into main Oct 15, 2026
204 of 207 checks passed
@steipete
steipete deleted the steipete/perf-micro-plugin-invocation-scope-20260919 branch October 15, 2026 20:39
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant