Skip to content

perf(gateway): reduce Control UI bootstrap blocking - #175752

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-boot-acorn-typebox-main-thread-20260919
Oct 17, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-boot-acorn-typebox-main-thread-20260919

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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. processSchema in 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

  • Regression reproduced before the change: bootstrap called OpenClawSchema.toJSONSchema() once. Afterward it calls it zero times while preserving MCP credential redaction and restricted-viewer omission.
  • Focused bootstrap and asset tests passed. Final asset rerun: 21 tests passed, 34.78 s Vitest wall time (mostly worker artifact preparation); includes static imports, re-exports, cycles, dynamic/missing/external exclusions, and optional parse failure. Bootstrap test: 37 ms. Changed-file format, lint, and git diff --check passed.
  • Independent Codex autoreview of the final change: scoped clean through P2; no actionable findings.
  • Four concurrent, core-swapped Chromium pairs rejected removing preload hints; the final implementation preserves the existing dependency graph expectations.
  • Four concurrent Linux split-core Gateway boot pairs passed: cold bootstrap 580.93 → 255.80 ms, paired mean −325.13 ms (56%); first-30-second main-thread CPU 2598.50 → 2135.56 ms, paired mean −462.94 ms (17.8%). Readiness was neutral: paired mean −8.54 ms.
  • Exact-head CI run 39057327019 and aggregate CI gate passed on 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; candidate 027336ba77154b93cbef1abbeebcc5373992bc9b. 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.

Pair Readiness B−A (ms) Main-thread CPU B−A (ms) Cold bootstrap B−A (ms) Acorn samples A→B processSchema samples A→B TypeBox samples A→B
1 -5.63 -377.22 -332.25 181→0 20→0 40→46
2 +29.27 -408.73 -326.54 159→0 18→0 38→46
3 +42.75 -495.64 -334.43 181→0 18→0 38→41
4 -100.56 -570.16 -307.29 185→0 21→0 45→47

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; every processSchema sample came through prepareControlUiBootstrapPreferences and full Zod JSON Schema conversion. Remaining TypeBox samples came mainly from listManagedPlugins → resolvePluginConfigEnablement during 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 17, 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 17, 2026 18:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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-17T18:18:30.304163Z 027336b 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: S labels Oct 17, 2026
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.
@steipete steipete changed the title perf(gateway): remove redundant bootstrap parsing perf(gateway): reduce Control UI bootstrap blocking Oct 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed docs Improvements or additions to documentation size: S labels Oct 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final implementation and paired boot evidence are current at 027336ba77154b93cbef1abbeebcc5373992bc9b. Static preload hints are preserved; Acorn parsing moves to the existing native esbuild service, and bootstrap skips full Zod JSON Schema conversion. Four concurrent, core-swapped pairs improved cold bootstrap by 325 ms and first-30-second main-thread CPU by 463 ms on average, with neutral readiness. Focused tests and independent review passed; detailed attribution and fixture limits are in the PR body.

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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 17, 2026
@steipete
steipete merged commit 0d03021 into main Oct 17, 2026
139 of 140 checks passed
@steipete
steipete deleted the steipete/perf-micro-boot-acorn-typebox-main-thread-20260919 branch October 17, 2026 18:28
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant