Skip to content

perf(ai): reuse request schema depth admission - #185159

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-tool-schema-projection-20260919
Oct 26, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-tool-schema-projection-20260919

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Provider request conversion repeats a full schema-depth walk immediately after request preparation has already bounded and detached the same schema, even on normalization-cache hits.

User Impact

Reduces allocation and CPU during repeated non-strict OpenAI tool conversion. Provider payloads, schema hashes, strict-mode selection, and mutable input validation retain their existing behavior.

Why This Change Was Made

Reuse membership in the existing synchronous preparation map as the depth-admission fact. Its owner restores the prior map when conversion returns, so the optimization adds no retained cache, invalidation mechanism, or provider policy. Direct inputs still pass through depth checking. Published schemas continue to use their existing immutable publication.

Runtime production delta: +9 lines. The small addition exposes the existing owner's preparation fact so the duplicate traversal can be removed without weakening the direct mutable-input boundary. The required non-test/non-doc diff is +187 lines: +9 runtime and +178 reproducible benchmark tooling. Simplification pass retained only this owner fact, one regression, and reproducible measurement.

Evidence

Acceptance rule, recorded before measurements: unchanged payload bytes and SHA-256 plus canonical schema fingerprint; repeated and fresh-run workloads improve allocation or CPU; published control is neutral. Timing is untraced, allocation is sampled separately. Two counterbalanced AB/BA pairs, 2,000 requests per arm per timing/allocation pass, Node 24.22.1 on macOS. Fresh-run mode creates 100 catalogs outside measurement and uses each for 20 requests. Strict mode verifies that strict: true is actually emitted. Baseline source: f6115599b4f3; the measured runtime patch is unchanged after rebasing.

Workload Sampled B/request: base → candidate CPU µs/request: base → candidate Mean paired allocation / CPU delta
40 repeated tools 912,715 → 462,544 753.95 → 543.30 −49.32% / −27.50%
80 repeated tools 1,823,826 → 923,300 1328.72 → 1064.03 −49.38% / −19.92%
80 tools across runs 2,014,538 → 1,117,305 1633.10 → 1349.66 −44.54% / −17.34%
80 strict tools 2,570,518 → 2,570,289 1601.19 → 1616.85 −0.009% / +0.97%
80 published tools, short control 91,245 → 91,523 37.84 → 45.00 +0.304% / +18.42%

The repeated 80-tool case saves 900,526 B and 264.69 µs CPU per request; fresh-run mode saves 897,234 B and 283.44 µs. Payload bytes/SHA-256 and canonical schema fingerprints match across all arms. Selected-mode payloads are also checked before and after warming outside measurements. The non-strict 80-tool payload is 56,951 bytes, SHA-256 9cff19f74526d9120bc578e9112474142840ea01f189c43efe9461f5914f7ed5.

The short published control is noisy: paired CPU deltas were +6.51% and +30.34%, while four identical-source A/A pairs produced +0.25%, +7.37%, +21.90%, and −1.21%. Lengthened 20,000-request AB/BA controls gave 36.56 → 31.65 µs CPU and 92,105 → 92,303 B/request (+198 B, +0.216%). This unchanged short-circuit path is treated as neutral, not a speedup or a regression. All original observations are included rather than discarded.

Local one-minute host load ranged 28.5–33.0 for the improved workloads. All processes were bounded below 30 seconds (maximum 16.52 seconds). The remote benchmark host's guard refused admission because load reached 139 and dirty memory exceeded 5 GB; no remote measurement ran, and the task sandbox/lock were cleaned up.

Reproduce using the committed script header, for example:

node --expose-gc --import ./scripts/tsx.mjs scripts/perf/tool-schema-request-admission-measure.ts --tools 80 --iterations 2000 --samples 1 --mode repeated

Use --mode across-runs, --mode published, or --strict for the other cases; run base/candidate in AB/BA order.

The regression fails on the base with one redundant traversal instead of zero. Candidate focused schema suites pass 52 tests, covering deep schemas, strict downgrade, mutable source updates, option isolation, quarantine/recovery, and scope expiry. The schema test command took 84.5 seconds, mostly cold worker preparation. Prompt-prefix stability and required import-closure tests also passed (40 tests; 238.9-second command). Core typecheck, changed-file lint/format, export-name collision guard, and diff checks passed.

Independent subagent review (autoreview route unavailable). The configured review-route preflight rejected the requested provider selection; no configuration was changed. The independent review checked the production owner, callers, lifecycle, and regression.

This is owner-boundary proof for a synchronous duplicate-work deletion. No whole-Gateway performance claim or production load test is made.

PR CI passed on final head da7ff9cabe29399456ee63efd1e57995546ef050: run 40419389706. All selected tests, typechecks, lint, prompt snapshots, boundary checks, and the CI gate passed. Automated code review also completed on this head with no findings.

@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 size: M labels Oct 26, 2026
@steipete
steipete marked this pull request as ready for review October 26, 2026 23:18
@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-26T23:25:05.727387Z da7ff9c 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.

@steipete
steipete force-pushed the steipete/perf-micro-tool-schema-projection-20260919 branch from 1b1d2b5 to da7ff9c Compare October 26, 2026 23:23
@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 26, 2026
@steipete
steipete merged commit ec113bc into main Oct 26, 2026
117 checks passed
@steipete
steipete deleted the steipete/perf-micro-tool-schema-projection-20260919 branch October 26, 2026 23:40
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
* perf(ai): reuse request schema depth admission

* test(perf): narrow published schema fixture to an object
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. scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant