Repository navigation
perf(build): halve warm rebuilds with hook filters, parallel asset hooks, cache-hit fixes and an optional worker bundle - #198664
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR reduces repeated build work and adds an opt-in way to omit sealed worker bundles from runtime-only builds. Example: A developer builds with OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 and OPENCLAW_BUILD_WORKER_DEPLOY_BUNDLE=0.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides useful build optimizations and fixes both previously reported blockers; no remaining actionable defect was found in the pinned diff. Priority: P2 Before mergeNone. FindingsNone. Provenance
Agent review detailsHow this fits togetherThe build orchestrator passes source files, plugin assets, and build settings through tsdown and existing artifact-cache owners to produce runtime distributions, declarations, and worker bundles. flowchart TD
A[Source and build settings] --> B[Build orchestrator]
B --> C[Plugin asset hooks]
B --> D[Filtered tsdown hooks]
B --> E[Existing artifact caches]
C --> F[Runtime distributions]
D --> F
E --> F
D --> G[Selected worker bundles]
Technical reviewBest possible solution: Retain these optimizations within the existing build owners, preserving default artifact completeness and the explicit runtime-only worker opt-out. Do we have a high-confidence way to reproduce the issue? Current-main source confirms repeated unfiltered callbacks, serial asset hooks, repeated input reads, and cache-hit reporting; the reported performance measurements were not independently rerun during this read-only review. Is this the best way to solve the issue? The change removes unnecessary work at existing boundaries, preserves transform bodies, and uses a bounded invocation-scoped digest map with producer-side invalidation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 897846bbe085. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceTests +37, Other +183. Total +220 across 24 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 14, 2026, 2:37 AM ET / 07:37 UTC (Revision 2). |
…kip JS Twelve build plugins registered unfiltered transform/load hooks that matched one or a few exact files, so Rolldown sent every module of ~90 configs through JavaScript (and several hooks realpath'd each id). The hooks now declare the same match as a native Rolldown filter; handler bodies are unchanged. Outputs of the no-declaration tsdown step are byte-identical (23,424 files, 3 A/B pairs); CPU 189 -> 179 s, wall 70 -> 64 s at load 56-80. Co-authored-by: obviyus <[email protected]>
…, ui:build and the worker bundle - run plugin asset build hooks four at a time; copy hooks stay serial - share per-file digests across external plugin cache signatures in one run - skip the report-only Control UI performance check on a ui:build cache hit - OPENCLAW_BUILD_WORKER_DEPLOY_BUNDLE=0 skips the sealed worker deploy entries in runtime-only builds; declaration, package and release builds always build them - evaluate the new Rolldown hook filters in the Bun standalone source adapter and point direct hook callers in tests at the filtered handlers Co-authored-by: obviyus <[email protected]>
…oks, cache-hit fixes and an optional worker bundle OpenClaw-Publication: 7f15f3b0-0cdf-85b3-a7ba-546a4b2eafd8
4514fbe to
73a8e19
Compare
Co-authored-by: obviyus <[email protected]>
…dle in full builds Rolldown normalizes module ids to forward slashes before evaluating hook filters, so filters built from Windows paths now normalize too, and the Bun standalone adapter matches the same way. Full, package and CI artifact profiles run tsdown without declarations, so they now pin the sealed worker deploy bundle on; only runtime-only builds honor the opt-out. Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 7c9038e. Warm rebuilds no longer push every module through JS hooks, run plugin asset hooks serially, re-hash shared sources per plugin, or re-measure UI bundles on cache hits; runtime-only builds can also skip the sealed worker bundle. Proof: full build byte-identical to main apart from build identity, 582 build tests green, and ClawSweeper's Windows-filter and package-worker findings fixed with regression tests. |
…oks, cache-hit fixes and an optional worker bundle (openclaw#198664) ## Problem A warm rebuild after a one-line source edit (`OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build`) takes about 4 minutes on a loaded 32-core Mac, mostly in work that repeats unchanged results: - Twelve build plugins register unfiltered `transform`/`load` hooks that match one or a few exact files. Rolldown therefore sends every module of ~90 configs through JavaScript, and several hooks `realpath` each id. - `plugins:assets:build` runs its plugin Control UI hooks one at a time (each a short esbuild process). - `external-plugins:local-dist` hits its per-plugin caches but still re-hashes the same SDK and core sources once per plugin: 66,258 file reads per pass for 12,965 unique files, done twice. - A `ui:build` cache hit still runs the report-only Control UI performance check (~20 s of gzip/brotli measurement) on bytes it already measured. - Runtime-only builds always build the sealed cloud-worker deploy bundle, about half of tsdown's CPU, and `check-cli-bootstrap-imports` then walks it. ## Solution - **Hook filters.** Each exact-match hook declares its match as a native Rolldown filter (`scripts/lib/rolldown-id-filter.mts`); handler bodies are unchanged. Filters normalize Windows paths to the forward-slash ids Rolldown matches against. The Bun standalone source adapter evaluates the same two filter shapes (id RegExp, code substring) and still rejects any other shape. - **Plugin asset hooks.** Build-phase hooks run four at a time; each writes only its own package's assets. Every running hook is joined before the step reports. Copy-phase hooks stay serial. - **External plugin signatures.** `hashInputFiles` accepts an optional per-run file-digest map. The step shares it across plugins and drops a plugin's own entries after its build, so regenerated package files are re-read. - **`ui:build` hit.** The report-only performance check runs only after a real build. The precompressed-assets check still runs on every hit, and restores still use APFS clones (`COPYFILE_FICLONE`). - **Worker deploy bundle.** `OPENCLAW_BUILD_WORKER_DEPLOY_BUNDLE=0` skips the sealed deploy entries, only together with `OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1`. Full, package, CI-artifact and release builds pin the bundle on in `build-all` (they run tsdown without declarations too), so only runtime-only builds honor the opt-out, and the local process helpers in `dist/worker/` are always built. tsdown's output clean removes any earlier bundle. Preparing a worker bundle from such a dist fails with the existing "OpenClaw worker deploy artifact is missing" error. The bootstrap check skips the worker artifact only when the flag is set and the entry is absent. Not changed: `runtime-postbuild` and `check-cli-bootstrap-imports` read tsdown's fresh output, so a content-keyed cache would miss on every source edit; the bootstrap check is ~1 s once the worker walk is skipped. ## Impact Measured on Studio (M3 Ultra, shared, load 40-80), `OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build`, warm caches, base `7b86e3888a75` vs this branch with `OPENCLAW_BUILD_WORKER_DEPLOY_BUNDLE=0`: | Warm rebuild | main | this PR | |---|---|---| | one `src/` edit (run 1) | 4m 04s | 1m 36s | | one `src/` edit (run 2) | 4m 15s | 2m 09s | | one `extensions/` edit | 3m 35s | 2m 01s | | no change | 3m 45s | 2m 28s | Per step for the `src/` edit: tsdown 91 s -> 32-42 s, `ui:build` 47-50 s -> 23-27 s, `plugins:assets:build` 16-25 s -> 4-5 s, `external-plugins:local-dist` 22-40 s -> 11-15 s, `check-cli-bootstrap-imports` 10-16 s -> ~1 s. Full cache-off `pnpm build` (declarations, worker bundle built): 6m 16.8s -> 4m 45.2s. ## Evidence - **Re-proven on this head (`73a8e1974e13`, rebased on `4ff01c8`):** full `--dts` build of this head vs full build of `4ff01c8`: 30,291 `dist`/`dist-runtime` files each; 11 differ, all build identity (stamps, `build-info.json`, `build-cache-inputs.json`, help-text commit, Control UI `index.html`/`sw.js*`) plus two Control UI source maps that differ only in Rolldown's checkout-path-derived `ROLLDOWN_FILE_URL_*` placeholder names (their JS is identical). All 705 declaration files are byte-identical. - **Tests on this head:** 18 files in `test/scripts` (the list above plus `crabbox-wrapper`, `ui-real-gateway-runner`, `ui-tsx-discovery`): 582 passed, 1 skipped; `build-all` passes separately. Timings below were taken on base `7b86e3888a75`; correctness proof and tests were rerun on the current head. - **Byte-identical full tier:** cache-off full `pnpm build` on base and branch, every dist file hashed: 28,193 files each; the only 10 differing files are build identity (`.buildstamp`, `.runtime-postbuildstamp`, `build-cache-inputs.json`, `build-info.json`, `cli-startup-metadata.json` help text with the commit id, Control UI `index.html`/`sw.js*`, and one Control UI source map that embeds the checkout path). - **Hook filters alone:** no-declaration tsdown step on base vs filters, 3 alternating pairs: 23,424 files, 0 differing in every pair; CPU 189 s -> 179 s. - **Worker skip:** after the skipped build, `dist/worker/` holds only `github-exec-launcher.mjs`, `service-child-group-anchor.mjs`, `service-child-relay.mjs`, `workspace-rsync-receiver.mjs` and the Windows helper; `prepareWorkerBundle` on that checkout rejects with "OpenClaw worker deploy artifact is missing; build the running package at …"; an isolated Gateway (private state, loopback, token auth) on that dist reports healthy in 17 s. - **Tests:** `build-all`, `build-artifact-cache`, `build-external-plugin-local-dist`, `bundled-plugin-assets`, `check-cli-bootstrap-imports`, `ui`, `tsdown-config`, `tsdown-runtime-config`, `worker-deploy-build-plugin`, `bun-standalone-source-{module-urls,transforms}`, `bun-standalone-worker-source-types`, `plugin-inventory-module-refs`, `public-session-locales`, `sqlite-schema-assets`, `state-read-worker-build`, `build-plugin-control-ui`; `tsgo -p tsconfig.scripts.json`. Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
A warm rebuild after a one-line source edit (
OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build) takes about 4 minutes on a loaded 32-core Mac, mostly in work that repeats unchanged results:transform/loadhooks that match one or a few exact files. Rolldown therefore sends every module of ~90 configs through JavaScript, and several hooksrealpatheach id.plugins:assets:buildruns its plugin Control UI hooks one at a time (each a short esbuild process).external-plugins:local-disthits its per-plugin caches but still re-hashes the same SDK and core sources once per plugin: 66,258 file reads per pass for 12,965 unique files, done twice.ui:buildcache hit still runs the report-only Control UI performance check (~20 s of gzip/brotli measurement) on bytes it already measured.check-cli-bootstrap-importsthen walks it.Solution
scripts/lib/rolldown-id-filter.mts); handler bodies are unchanged. The Bun standalone source adapter evaluates the same two filter shapes (id RegExp, code substring) and still rejects any other shape.hashInputFilesaccepts an optional per-run file-digest map. The step shares it across plugins and drops a plugin's own entries after its build, so regenerated package files are re-read.ui:buildhit. The report-only performance check runs only after a real build. The precompressed-assets check still runs on every hit, and restores still use APFS clones (COPYFILE_FICLONE).OPENCLAW_BUILD_WORKER_DEPLOY_BUNDLE=0skips the sealed deploy entries, only together withOPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1. Declaration, package and release builds always build them, and the local process helpers indist/worker/are always built. tsdown's output clean removes any earlier bundle. Preparing a worker bundle from such a dist fails with the existing "OpenClaw worker deploy artifact is missing" error. The bootstrap check skips the worker artifact only when the flag is set and the entry is absent.Not changed:
runtime-postbuildandcheck-cli-bootstrap-importsread tsdown's fresh output, so a content-keyed cache would miss on every source edit; the bootstrap check is ~1 s once the worker walk is skipped.Impact
Measured on Studio (M3 Ultra, shared, load 40-80),
OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build, warm caches, base77a0a8426513vs this branch withOPENCLAW_BUILD_WORKER_DEPLOY_BUNDLE=0:src/edit (run 1)src/edit (run 2)extensions/editPer step for the
src/edit: tsdown 91 s -> 32-42 s,ui:build47-50 s -> 23-27 s,plugins:assets:build16-25 s -> 4-5 s,external-plugins:local-dist22-40 s -> 11-15 s,check-cli-bootstrap-imports10-16 s -> ~1 s.Full cache-off
pnpm build(declarations, worker bundle built): 6m 16.8s -> 4m 45.2s.Evidence
Re-proven on this head (
73a8e1974e13, rebased on3256fe1): full--dtsbuild of this head vs full build of3256fe1: 30,291dist/dist-runtimefiles each; 11 differ, all build identity (stamps,build-info.json,build-cache-inputs.json, help-text commit, Control UIindex.html/sw.js*) plus two Control UI source maps that differ only in Rolldown's checkout-path-derivedROLLDOWN_FILE_URL_*placeholder names (their JS is identical). All 705 declaration files are byte-identical.Tests on this head: 18 files in
test/scripts(the list above pluscrabbox-wrapper,ui-real-gateway-runner,ui-tsx-discovery): 582 passed, 1 skipped;build-allpasses separately.Timings below were taken on base
77a0a8426513; correctness proof and tests were rerun on the current head.Byte-identical full tier: cache-off full
pnpm buildon base and branch, every dist file hashed: 28,193 files each; the only 10 differing files are build identity (.buildstamp,.runtime-postbuildstamp,build-cache-inputs.json,build-info.json,cli-startup-metadata.jsonhelp text with the commit id, Control UIindex.html/sw.js*, and one Control UI source map that embeds the checkout path).Hook filters alone: no-declaration tsdown step on base vs filters, 3 alternating pairs: 23,424 files, 0 differing in every pair; CPU 189 s -> 179 s.
Worker skip: after the skipped build,
dist/worker/holds onlygithub-exec-launcher.mjs,service-child-group-anchor.mjs,service-child-relay.mjs,workspace-rsync-receiver.mjsand the Windows helper;prepareWorkerBundleon that checkout rejects with "OpenClaw worker deploy artifact is missing; build the running package at …"; an isolated Gateway (private state, loopback, token auth) on that dist reports healthy in 17 s.Tests:
build-all,build-artifact-cache,build-external-plugin-local-dist,bundled-plugin-assets,check-cli-bootstrap-imports,ui,tsdown-config,tsdown-runtime-config,worker-deploy-build-plugin,bun-standalone-source-{module-urls,transforms},bun-standalone-worker-source-types,plugin-inventory-module-refs,public-session-locales,sqlite-schema-assets,state-read-worker-build,build-plugin-control-ui;tsgo -p tsconfig.scripts.json.