Repository navigation
perf(gateway): reduce Control UI bootstrap blocking - #175752
Conversation
Let the browser resolve plugin module dependencies from the existing entry preload, and use core redaction hints without materializing the full configuration JSON Schema during bootstrap.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
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. |
Cold-browser measurements showed that removing transitive preload hints added roughly 45 ms to activation with 20 ms response latency. Keep those hints and extract them using the existing esbuild native service instead of parsing an Acorn AST on the Gateway main thread.
|
@clawsweeper re-review Final implementation and paired boot evidence are current at |
|
🦞👀 Re-review progress:
|
* perf(gateway): remove redundant bootstrap parsing Let the browser resolve plugin module dependencies from the existing entry preload, and use core redaction hints without materializing the full configuration JSON Schema during bootstrap. * perf(gateway): preserve preload hints with native import scanning Cold-browser measurements showed that removing transitive preload hints added roughly 45 ms to activation with 20 ms response latency. Keep those hints and extract them using the existing esbuild native service instead of parsing an Acorn AST on the Gateway main thread.
What Problem This Solves
Opening the Control UI immediately after Gateway readiness parses plugin browser bundles on the main thread and materializes the complete configuration JSON Schema just to redact a small bootstrap preference projection.
User Impact
Bootstrap keeps the same preference redaction, plugin asset authorization, immutable revisions, reload behavior, and static dependency preload hints. Import discovery runs through the existing esbuild native service; browser JavaScript is neither executed nor rewritten on disk.
Why This Change Was Made
Use esbuild's import metadata instead of creating full Acorn ASTs on the Gateway main thread. Keep the existing catalog owner and snapshot lifetime. For bootstrap's core-only config projection, reuse core sensitivity hints without constructing the full core/plugin JSON Schema.
RPC validators already compile lazily once; plugin config validators already cache by schema contents.
processSchemain the reported profile is Zod JSON Schema conversion, not TypeBox compilation.Production delta: +2 lines; tests: +3 lines. The retained preload contract accounts for the small growth: a concurrent cold-browser comparison with 20 ms response delays showed roughly 45 ms slower activation without transitive hints. The final change preserves those hints and removes the main-thread AST. No dependencies, config options, or database changes.
Evidence
OpenClawSchema.toJSONSchema()once. Afterward it calls it zero times while preserving MCP credential redaction and restricted-viewer omission.git diff --checkpassed.027336ba77154b93cbef1abbeebcc5373992bc9b; code/security checks passed. No CI rerun or inherited-failure exception was needed. No Testbox/Crabbox lease used, per the current validation rule.Paired Boot Measurement
Baseline
df0358cdd5f7e8525a9c610dd05745806eaf0e50; candidate027336ba77154b93cbef1abbeebcc5373992bc9b. Four simultaneous A/B pairs held the exclusive measurement lock. Each process had 16 cores; assignments alternated between 96–111 and 112–127. Both sides used the same start timestamp, separate state and loopback ports, and identical dependencies. Decisions use B−A within each pair.The synthetic inventory contains 5,000 sessions, 6,000 retained runs, 200 approvals, 100 disabled cron jobs and 12 projects. Transcript volume is reduced to 4 MiB; each fixture has approximately 39 MiB agent DB plus 11 MiB state DB. MCP Relay and Workboard are the active bundled browser UIs. ClawRouter and X remain inactive without their provider/channel configuration. This is an inventory-shaped boot measurement, not a full production plugin/configuration or large-transcript reproduction.
Each Gateway received ten concurrent bootstrap requests and ten fresh WebSocket connections immediately after ready, repeated at ready+15 s (20 bootstrap requests and 40 connect/catalog RPCs per process). CPU profiles began before ready; the table counts main-thread SELF samples only in the next 30 s, at a nominal 1 ms interval.
Warm bootstrap averaged 9.95 → 10.68 ms (paired +0.73 ms). Both sides advertised the same preload-hint count for every response. Recorded per-pair mean non-idle CPU across the measurement cores was 7.40%, 6.82%, 7.54%, and 9.99%; this includes the benchmark and concurrent outside load, and is context rather than an exclusion criterion. All owned Gateway processes exited cleanly.
Attribution: Acorn samples came from
staticBrowserImports; everyprocessSchemasample came throughprepareControlUiBootstrapPreferencesand full Zod JSON Schema conversion. Remaining TypeBox samples came mainly fromlistManagedPlugins → resolvePluginConfigEnablementduring inventory prewarming, plus first-use RPC validation. Neither side had samples in these three categories during the second 15-second half. Those existing validators already compile once per cached schema; this PR adds no competing cache or changes to their validation boundary. Tool argument validators also already cache by schema and reference-root identity; agent tool execution was not exercised here.The existing plugin-record catalog reuses discovery within a process, including reconnects, but is not persisted across restarts. This change uses the existing native esbuild service for the cold parse instead of adding a persistent parser cache. The main-thread CPU reduction does not claim total-system CPU savings: native parsing still consumes CPU outside the Gateway thread.
Measurement preparation used sequential synthetic fixture generation and isolated source-performance builds. Both sides shared the same external dependency graph, with task-owned missing dependencies; this was not an exact frozen-lockfile installation. PR CI provides the exact package/build/typecheck/test gates. One initial pair was excluded because the fixture incorrectly expected two inactive plugin UIs; both sides failed the identical assertion and shut down cleanly before measurement completion.