[PR #4360] [MERGED] perf(schema): reduce retained integer validator allocations #6201

Closed
opened 2026-10-31 01:12:39 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4360
Author: @leeguooooo
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @gensokyo-dev

Base: main ← Head: perf/mcp-runtime-memory


📝 Commits (10+)

  • 1cae1ff perf(schema): 直接构造整数校验器以减少常驻内存
  • 5452bd0 Merge origin/main into perf/mcp-runtime-memory
  • f6d4471 Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory
  • 6df6037 fix(cli): 保留命令行整数参数的字符串转换
  • 5f1e94a Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory
  • 37bd612 Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory
  • 65f12e0 Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory
  • 555dc69 Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory
  • 71abced chore(schema): 同步主干并保留整数校验分配优化
  • 6d4c812 perf(schema): port integer allocation reduction to current owners

📊 Changes

182 files changed (+9562 additions, -1329 deletions)

View changed files

📝 experiments/analysis-efficiency/mcp-input-catalog.mjs (+27 -2)
➕ experiments/analysis-efficiency/mcp-integer-allocation.json (+7749 -0)
➕ experiments/analysis-efficiency/mcp-integer-allocation.md (+143 -0)
➕ experiments/analysis-efficiency/mcp-integer-report.mjs (+212 -0)
➕ experiments/analysis-efficiency/mcp-retained-heap.mjs (+107 -0)
📝 experiments/analysis-efficiency/mcp-startup-costs.py (+36 -3)
📝 src/android/JadxProtocol.ts (+7 -7)
📝 src/browser/PlaywrightElectronActiveActions.ts (+1 -1)
📝 src/browser/PlaywrightScenarioArtifacts.ts (+1 -1)
📝 src/browser/execution/CdpEventListeners.ts (+3 -3)
📝 src/browser/execution/CdpRuntimeProtocol.ts (+1 -1)
📝 src/config/mcpResponseBudget.ts (+1 -1)
📝 src/config/providerStartupTimeout.ts (+1 -1)
📝 src/contracts/artifactToolContracts.ts (+3 -3)
📝 src/contracts/cutterToolContracts.ts (+4 -4)
📝 src/contracts/enhancedInputs.ts (+4 -9)
📝 src/contracts/fridaToolContracts.ts (+4 -5)
📝 src/contracts/gdbToolContracts.ts (+1 -1)
📝 src/contracts/hopperMemoryContracts.ts (+2 -2)
📝 src/contracts/sessionToolSchemas.ts (+1 -3)

...and 80 more files

📄 Description

Summary

Canonical integer validators retain a number schema plus a separate format-check schema. Construct the integer format directly at 1,247 existing declarations, preserving current shared owners, bounds, defaults, refinements and metadata. CLI schemas and shared inputs requiring Incur numeric argv coercion keep the chained construction. No tool, provider, target authority, Evidence or advertised-schema change.

Closes #6236. Synchronized with main@4a4bbab3c; production source is identical to the measured 461f342c7 after later evidence/accounting commits.

Measured completed tasks

Official Alpine ripgrep 14.1.1-r0 / Zellij 0.40.0-r0, independent ELF/section/zlib/JSON oracles (42/422 packages, 88/1,063 edges). Actual SDK tasks select serde facts, repeat retained reads, reject a negative offset, export/verify complete parent Evidence and confirm unchanged catalogs. All 72 normal trials, 12 separate heap diagnostics and four warm priming runs pass.

Three alternating pairs per condition. Separately instrumented inspector/forced-GC retained REA V8 heap (MiB, baseline → candidate):

Inputs Median MiB Baseline / candidate ranges
default 189.835 → 180.242 189.823–189.855 / 180.208–180.366
full 191.260 → 181.693 191.165–191.304 / 181.588–181.848

About 9.6 MiB less retained heap in these diagnostics; inspector perturbation is included. Normal tasks run without inspector/GC. Default cold Zellij SDK span is 5.998 → 5.991 s; whole-family wall/CPU/peak are 7.876 → 7.373 s / 7.623 → 7.134 s / 812.2 → 810.5 MiB. Whole-family figures include source/compiled binding: asymmetric audit spans account for most of the apparent startup/time improvement. Per-span CPU is unmeasured. No general latency or peak-memory reduction claim. The slower full/warm Zellij condition in both roles is retained without a causal attribution.

Both profiles preserve all 213 advertisements byte-for-byte before/after materialization. Input-directory estimates remain 49,670 / 205,744 cl100k_base tokens; complete-task projections, raw directory costs, every call and ranges are in the receipts. Actual model usage is unmeasured.

Serial Linux x64, Node 24.18.0/npm 11.16.0, locked Zod 4.4.3/Incur 0.6.1; 1 CPU, 4 GiB hard/3 GiB early stop/no swap. Fresh HOME/processes; cold disables server compile cache, warm primes a role/profile cache. OS page cache and cache hit rate are unmeasured. Every trial binds clean source, all compiled JS/JSON, producers and guard counters before/after; no OOM or payload leftovers.

Methods and all profiles · All receipts.

Validation

  • Both runtime builds, all six static checks plus architecture guards and six docs checks/nine documentation conformance tests pass. Before the final main sync: 5,972 tests across 323 files pass, four skip; after sync: 77 affected producer/CLI/MCP tests pass and all 974 installed-Incur parser cases across 104 numeric fields/160 registered leaf commands match again.
  • All 175 touched source files are AST-token equivalent after normalizing integer construction/formatting. Seven boundary variants match parsed values and exact issues in 126 cases; 14 draft-07/2020-12 projections match. SDK schema/profile/example checks pass. Real public-artifact answers and complete Evidence identities remain identical.
  • Five report sections now come from one JSON-backed producer. The docs gate checks actual receipt conformance, rejects stale normal/heap values and refuses missing markers before writing. The valid Greptile stale-table finding is fixed; raw measurements are unchanged.
  • Inspector PID mismatch is rejected; removing only the guard makes the negative oracle fail, using only the same owned REA endpoint. Aggregation refuses GC-contaminated normal trials before output. Historical #4424 receipt metrics remain unchanged with additive SDK-span accounting.
  • Coverage is static Rust metadata plus existing boundary/CLI tests and 12 real Rizin/GitHub CLI tasks using existing native batching; real Hopper/Ghidra/IDA, Android devices, other providers, ordinary uninstrumented retained heap and foreign-OS workflows beyond the executed CI qualification are unverified in this local audit. Earlier macOS measurements describe a different revision/platform. Initial catalog-test metadata and two invalid affected-test paths were corrected; those failed invocations are not counted as passing tests. Current-head CI and Greptile pass; no unresolved review threads remain. The earlier macOS signature timeout passed on the unchanged-runtime current head without a source/timeout adjustment. Codex review could not complete because repository review usage limits were reached (bot result). AI assistance: Codex.

Author readiness

Human owner: @leeguooooo

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4360 **Author:** [@leeguooooo](https://github.com/leeguooooo) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@gensokyo-dev](https://github.com/gensokyo-dev) **Base:** `main` ← **Head:** `perf/mcp-runtime-memory` --- ### 📝 Commits (10+) - [`1cae1ff`](https://github.com/morluto/rea/commit/1cae1fff63c54a5d8a5f54f360f4b16bd61ca596) perf(schema): 直接构造整数校验器以减少常驻内存 - [`5452bd0`](https://github.com/morluto/rea/commit/5452bd0f5e7058d9fa2825864667e95b7c5c689e) Merge origin/main into perf/mcp-runtime-memory - [`f6d4471`](https://github.com/morluto/rea/commit/f6d4471de5bb46003a2b450174512a29393275f5) Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory - [`6df6037`](https://github.com/morluto/rea/commit/6df60370d110f884a2822389e92debf0190614b9) fix(cli): 保留命令行整数参数的字符串转换 - [`5f1e94a`](https://github.com/morluto/rea/commit/5f1e94a3a18b20975e8298c8b800158b4fc3ac45) Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory - [`37bd612`](https://github.com/morluto/rea/commit/37bd6125333c7141aff77f6ecdee9c0acbc6de68) Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory - [`65f12e0`](https://github.com/morluto/rea/commit/65f12e0af9425cc9eca6da49e3194a58c9cbf904) Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory - [`555dc69`](https://github.com/morluto/rea/commit/555dc69fbc723b43ab256b0d57360692ebaa4d41) Merge remote-tracking branch 'origin/main' into perf/mcp-runtime-memory - [`71abced`](https://github.com/morluto/rea/commit/71abcedd4dbefd0107b8befc7b5f4ca7f783e70b) chore(schema): 同步主干并保留整数校验分配优化 - [`6d4c812`](https://github.com/morluto/rea/commit/6d4c812f62854a771430ea8e93d2865820fabb1a) perf(schema): port integer allocation reduction to current owners ### 📊 Changes **182 files changed** (+9562 additions, -1329 deletions) <details> <summary>View changed files</summary> 📝 `experiments/analysis-efficiency/mcp-input-catalog.mjs` (+27 -2) ➕ `experiments/analysis-efficiency/mcp-integer-allocation.json` (+7749 -0) ➕ `experiments/analysis-efficiency/mcp-integer-allocation.md` (+143 -0) ➕ `experiments/analysis-efficiency/mcp-integer-report.mjs` (+212 -0) ➕ `experiments/analysis-efficiency/mcp-retained-heap.mjs` (+107 -0) 📝 `experiments/analysis-efficiency/mcp-startup-costs.py` (+36 -3) 📝 `src/android/JadxProtocol.ts` (+7 -7) 📝 `src/browser/PlaywrightElectronActiveActions.ts` (+1 -1) 📝 `src/browser/PlaywrightScenarioArtifacts.ts` (+1 -1) 📝 `src/browser/execution/CdpEventListeners.ts` (+3 -3) 📝 `src/browser/execution/CdpRuntimeProtocol.ts` (+1 -1) 📝 `src/config/mcpResponseBudget.ts` (+1 -1) 📝 `src/config/providerStartupTimeout.ts` (+1 -1) 📝 `src/contracts/artifactToolContracts.ts` (+3 -3) 📝 `src/contracts/cutterToolContracts.ts` (+4 -4) 📝 `src/contracts/enhancedInputs.ts` (+4 -9) 📝 `src/contracts/fridaToolContracts.ts` (+4 -5) 📝 `src/contracts/gdbToolContracts.ts` (+1 -1) 📝 `src/contracts/hopperMemoryContracts.ts` (+2 -2) 📝 `src/contracts/sessionToolSchemas.ts` (+1 -3) _...and 80 more files_ </details> ### 📄 Description ## Summary Canonical integer validators retain a number schema plus a separate format-check schema. Construct the integer format directly at 1,247 existing declarations, preserving current shared owners, bounds, defaults, refinements and metadata. CLI schemas and shared inputs requiring Incur numeric argv coercion keep the chained construction. No tool, provider, target authority, Evidence or advertised-schema change. Closes #6236. Synchronized with `main@4a4bbab3c`; production source is identical to the measured `461f342c7` after later evidence/accounting commits. ## Measured completed tasks Official Alpine ripgrep 14.1.1-r0 / Zellij 0.40.0-r0, independent ELF/section/zlib/JSON oracles (42/422 packages, 88/1,063 edges). Actual SDK tasks select serde facts, repeat retained reads, reject a negative offset, export/verify complete parent Evidence and confirm unchanged catalogs. All 72 normal trials, 12 separate heap diagnostics and four warm priming runs pass. Three alternating pairs per condition. Separately instrumented inspector/forced-GC retained REA V8 heap (MiB, baseline → candidate): | Inputs | Median MiB | Baseline / candidate ranges | | --- | ---: | ---: | | default | 189.835 → 180.242 | 189.823–189.855 / 180.208–180.366 | | full | 191.260 → 181.693 | 191.165–191.304 / 181.588–181.848 | About 9.6 MiB less retained heap in these diagnostics; inspector perturbation is included. Normal tasks run without inspector/GC. Default cold Zellij SDK span is 5.998 → 5.991 s; whole-family wall/CPU/peak are 7.876 → 7.373 s / 7.623 → 7.134 s / 812.2 → 810.5 MiB. Whole-family figures include source/compiled binding: asymmetric audit spans account for most of the apparent startup/time improvement. Per-span CPU is unmeasured. No general latency or peak-memory reduction claim. The slower full/warm Zellij condition in both roles is retained without a causal attribution. Both profiles preserve all 213 advertisements byte-for-byte before/after materialization. Input-directory estimates remain 49,670 / 205,744 cl100k_base tokens; complete-task projections, raw directory costs, every call and ranges are in the receipts. Actual model usage is unmeasured. Serial Linux x64, Node 24.18.0/npm 11.16.0, locked Zod 4.4.3/Incur 0.6.1; 1 CPU, 4 GiB hard/3 GiB early stop/no swap. Fresh HOME/processes; cold disables server compile cache, warm primes a role/profile cache. OS page cache and cache hit rate are unmeasured. Every trial binds clean source, all compiled JS/JSON, producers and guard counters before/after; no OOM or payload leftovers. [Methods and all profiles](https://github.com/leeguooooo/rea/blob/ed018b4a8204beec3368a69a3fca9333c4f1e161/experiments/analysis-efficiency/mcp-integer-allocation.md) · [All receipts](https://github.com/leeguooooo/rea/blob/ed018b4a8204beec3368a69a3fca9333c4f1e161/experiments/analysis-efficiency/mcp-integer-allocation.json). ## Validation - Both runtime builds, all six static checks plus architecture guards and six docs checks/nine documentation conformance tests pass. Before the final main sync: 5,972 tests across 323 files pass, four skip; after sync: 77 affected producer/CLI/MCP tests pass and all 974 installed-Incur parser cases across 104 numeric fields/160 registered leaf commands match again. - All 175 touched source files are AST-token equivalent after normalizing integer construction/formatting. Seven boundary variants match parsed values and exact issues in 126 cases; 14 draft-07/2020-12 projections match. SDK schema/profile/example checks pass. Real public-artifact answers and complete Evidence identities remain identical. - Five report sections now come from one JSON-backed producer. The docs gate checks actual receipt conformance, rejects stale normal/heap values and refuses missing markers before writing. The valid Greptile stale-table finding is fixed; raw measurements are unchanged. - Inspector PID mismatch is rejected; removing only the guard makes the negative oracle fail, using only the same owned REA endpoint. Aggregation refuses GC-contaminated normal trials before output. Historical #4424 receipt metrics remain unchanged with additive SDK-span accounting. - Coverage is static Rust metadata plus existing boundary/CLI tests and [12 real Rizin/GitHub CLI tasks](https://github.com/morluto/rea/pull/4360#issuecomment-6333201024) using existing native batching; real Hopper/Ghidra/IDA, Android devices, other providers, ordinary uninstrumented retained heap and foreign-OS workflows beyond the executed CI qualification are unverified in this local audit. Earlier macOS measurements describe a different revision/platform. Initial catalog-test metadata and two invalid affected-test paths were corrected; those failed invocations are not counted as passing tests. Current-head CI and Greptile pass; no unresolved review threads remain. The earlier macOS signature timeout passed on the unchanged-runtime current head without a source/timeout adjustment. Codex review could not complete because repository review usage limits were reached ([bot result](https://github.com/morluto/rea/pull/4360#issuecomment-6332914023)). AI assistance: Codex. ## Author readiness Human owner: @leeguooooo - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:12:39 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6201
No description provided.