Repository navigation
perf(build): emit tsdown declarations in one native compiler command-line pass - #198661
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 changes before merge. What this changesThis PR moves tsdown declaration emission to a native compiler CLI pass and enables parallel emission with stable type ordering. Example: Run a cache-disabled pnpm build.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep this PR open: the build optimization is useful, but the inherited-configuration boundary finding remains actionable. Priority: P2 Before merge
Findings
Provenance
Agent review detailsHow this fits togetherThe build tooling turns selected TypeScript roots and compiler configuration into declarations, source maps, and compiler-input receipts before staged publication. flowchart LR
A[Build command] --> B[Declaration writer]
B --> C[Cache snapshot]
B --> D[Native declaration emitter]
D --> E[tsgo compiler]
E --> F[Input admission]
F --> G[Staged declaration publication]
Technical reviewBest possible solution: Keep the CLI optimization while using the existing bounded configuration reader to admit the complete inherited configuration chain. Do we have a high-confidence way to reproduce the issue? Source inspection establishes that an outside inherited config containing only compiler options can affect a successful CLI emit without appearing in --listFiles; no target code was executed. Is this the best way to solve the issue? Removing filesystem callbacks from the expensive compile is reasonable, but source membership cannot replace admission of configuration inputs. Full review comments:
Overall correctness: patch is incorrect 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. EvidenceAcceptance criteria:
What I checked:
PR surfaceTests +16, Other +135. Total +151 across 4 files. Added test files: 0. 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. 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:36 AM ET / 07:36 UTC (Revision 2). |
…line pass The declaration emitter routed every compiler read through the native API's filesystem callbacks and forced a single-threaded emit. tsdown declaration builds now run one tsgo command-line pass, in parallel when stable type ordering is on, and take their inputs from --listFiles. Inputs outside the checkout still fail the build, now as a post-check on the files the compiler read. The writer keys every package.json and tsconfig plus the lockfile, which covers the manifests and failed probes the command line does not report. Two boundary behaviors change: an optional import that reaches a parent-directory install now fails with the escaped path instead of being hidden, and a parent-directory link that resolves back into the checkout builds from that checkout content. API baselines keep the API path for their declaration-only diagnostics. Co-authored-by: obviyus <[email protected]>
…line pass OpenClaw-Publication: 710a6ce2-0938-8665-8f11-5f27040dc82e
…emits Read dependency files resolve to versioned node_modules/.pnpm paths, so a dependency change already changes the inputs; the lockfile key only caused needless misses. The compiler creates its output directory only when it emits, so a compile with nothing to emit no longer fails scanning it. Co-authored-by: obviyus <[email protected]>
5abbb7d to
4d933d0
Compare
Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…ation pass The command-line pass read inherited configs directly, so a checkout config extending a base outside the checkout could change emit unnoticed. The bounded config reader now admits the whole extends chain first, as the API path did. Co-authored-by: obviyus <[email protected]>
|
Landed in 5a7d171. Declarations now come from one native compiler pass that reads the checkout directly (and checks/emits in parallel under stable type ordering) instead of routing every read through the API filesystem callbacks: write-unified-entry-dts 2m05s -> 1m20s, tsdown-packages 60s -> 33s. Proof: all 705 .d.ts files byte-identical to main, 119 emitter tests green, and the inherited-config boundary from the last review restored with a regression test. |
…line pass (openclaw#198661) ## Problem `write-unified-entry-dts` is the slowest step of a full build (~2 min on a 32-core Mac). The native declaration emitter routes every compiler read through the TypeScript 7 API's filesystem callbacks and forces `singleThreaded` emit. A plain `tsgo` pass over the same roots emits the same declarations in 17-27 s in parallel, versus 44-52 s single-threaded. ## Solution - tsdown declaration builds run one `tsgo -p <leaf config> --listFiles` pass. The leaf config sits beside its base, so `${configDir}`, relative overrides and default type roots keep the compiler's interpretation; the default type roots are bounded to the checkout. - Emit is parallel when `stableTypeOrdering` is on (the unified build sets it), otherwise single-threaded as before. The readonly-modifier race that motivated `singleThreaded` does not occur with stable type ordering: 12 emits of the full declaration graph (10 parallel at load 60-89, 2 single-threaded) produced 15,803 `.d.ts` files with one combined hash. - Before the pass, the bounded config reader admits the complete `extends` chain, so a checkout config cannot inherit emit-affecting options from outside the checkout (the API path denied that read; the build fails closed with `TS5083: Cannot read file`). Test: `rejects a checkout config that inherits options from outside the checkout`. - Inputs come from `--listFiles`. The checkout boundary is now a post-check: every file the compiler read must be physically inside the checkout, and escaped inputs are reported before type errors. - The writer's cache key now covers every `package.json` and `tsconfig*.json`, because the command line does not report consulted manifests or failed resolution probes. The lockfile is deliberately not keyed: `--listFiles` reports dependency files at their versioned `node_modules/.pnpm/<pkg>@<version>/` paths (all 3,877 dependency inputs of `tsconfig.core.json`), so a dependency change already changes the inputs, and lockfile-only edits keep hitting the CI build-all cache. - A compile with nothing to emit no longer fails: the compiler creates its output directory only when it emits. - API baselines (`diagnostics: "declarations"`, sometimes a historical compiler) keep the API path unchanged. ### Behavior changes (intentional, pinned by tests) 1. **Parent-install shadowing now fails loudly.** An optional SDK relative import that reaches a parent-directory `node_modules` used to be hidden by the virtual filesystem; it now fails with `Declaration input escapes checkout: <path>`. Test: `fails closed when optional SDK relative imports reach a parent install`. 2. **A parent-directory package link that resolves back into the checkout now builds.** The compiler reports the real path it read, which is checkout content, so the output is correct; the old path refused the outside spelling. Test: `builds through a parent package link that resolves back inside the checkout`. Test rewrites: receipts no longer list consulted `package.json` files; the directory-alias test now proves that editing such a manifest re-keys the cache (`cache miss`). The cold-sibling build-order test sequences on the compiler subprocess instead of patching `Program.prototype.emitToString`. ## Impact Full cache-off `pnpm build`, one run each at load 36-45: `write-unified-entry-dts` 2m 4.7s -> 1m 20.3s, `tsdown-packages` 59.9 s -> 32.7 s, total 6m 27s -> 5m 24s. Single runs on a shared host; the per-step deltas are larger than the run-to-run noise we observed. ## Evidence - Byte-identical on this head (`4d933d0`, rebased on `4ff01c8`): full builds of the PR head and of `4ff01c8`. All 705 declaration files (`dist`, `dist-runtime`, `packages/*/dist`, extensions) are byte-identical. Across all 30,291 `dist`/`dist-runtime` files, 9 differ, all build identity: stamps, `build-info.json`, the commit in help text and its signature, step cache-input hashes (which hash the changed scripts), and the Control UI service worker. - Tests on this head: all 15 declaration/tsdown files in `test/scripts` pass (254 passed, 5 skipped), including `native-declaration-boundary`, `tsdown-declaration-resolution`, `native-declaration-subprocess`, `declaration-stage` and `tsdown-config`. - Determinism: 12 emits of the full declaration graph (10 parallel under load) produced one combined hash. Co-authored-by: Ayaan Zaidi <[email protected]>
Revert PR #198661 on the release candidate as explicitly requested by Dallin before the next FRV. Preserve the later #198774 relative-path optimization and all other release repairs. This reverts commit 5a7d171. Co-authored-by: RomneyDa <[email protected]>
) * fix(build): run the declaration pass single-threaded unless the build heap is uncapped The parallel native declaration pass (#198661) holds Go memory outside --max-old-space-size. A cold build of main is OOM-killed in that pass in an 8 GiB container even with nothing else running; the single-threaded pass completes there. Parallel emit now needs the build owner's uncapped default heap, which it grants only when memory is ample. * test(build): prove both declaration modes emit identical output Compare the capped single-threaded and uncapped parallel passes in one fixture, keep the compiles running on Windows, and document which hosts stay single-threaded. * fix(build): admit parallel declarations from the planned old space, not the total heap V8's heap_size_limit adds the young generation, so a planner-capped 12287 MB old space still read as uncapped. Read the --max-old-space-size the build owner wrote instead, and keep the test wrapper's paths out of shell source. * fix(build): take declaration threading from the planned heap budget build-all hands every build child its frozen budget in OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB. Reading Node heap flags could still admit the parallel pass when an inherited underscored alias survived the planner's rewrite. * refactor(build): let tsdown-build hand its frozen heap budget to every child tsdown-build now exports OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB itself, so direct tsdown-build runs carry the budget that build-all used to add, and the declaration emitter shares the owner's uncapped-heap threshold instead of copying it.
…claw#201901) * fix(build): run the declaration pass single-threaded unless the build heap is uncapped The parallel native declaration pass (openclaw#198661) holds Go memory outside --max-old-space-size. A cold build of main is OOM-killed in that pass in an 8 GiB container even with nothing else running; the single-threaded pass completes there. Parallel emit now needs the build owner's uncapped default heap, which it grants only when memory is ample. * test(build): prove both declaration modes emit identical output Compare the capped single-threaded and uncapped parallel passes in one fixture, keep the compiles running on Windows, and document which hosts stay single-threaded. * fix(build): admit parallel declarations from the planned old space, not the total heap V8's heap_size_limit adds the young generation, so a planner-capped 12287 MB old space still read as uncapped. Read the --max-old-space-size the build owner wrote instead, and keep the test wrapper's paths out of shell source. * fix(build): take declaration threading from the planned heap budget build-all hands every build child its frozen budget in OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB. Reading Node heap flags could still admit the parallel pass when an inherited underscored alias survived the planner's rewrite. * refactor(build): let tsdown-build hand its frozen heap budget to every child tsdown-build now exports OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB itself, so direct tsdown-build runs carry the budget that build-all used to add, and the declaration emitter shares the owner's uncapped-heap threshold instead of copying it.
Problem
write-unified-entry-dtsis the slowest step of a full build (~2 min on a 32-core Mac). The native declaration emitter routes every compiler read through the TypeScript 7 API's filesystem callbacks and forcessingleThreadedemit. A plaintsgopass over the same roots emits the same declarations in 17-27 s in parallel, versus 44-52 s single-threaded.Solution
tsgo -p <leaf config> --listFilespass. The leaf config sits beside its base, so${configDir}, relative overrides and default type roots keep the compiler's interpretation; the default type roots are bounded to the checkout.stableTypeOrderingis on (the unified build sets it), otherwise single-threaded as before. The readonly-modifier race that motivatedsingleThreadeddoes not occur with stable type ordering: 12 emits of the full declaration graph (10 parallel at load 60-89, 2 single-threaded) produced 15,803.d.tsfiles with one combined hash.extendschain, so a checkout config cannot inherit emit-affecting options from outside the checkout (the API path denied that read; the build fails closed withTS5083: Cannot read file). Test:rejects a checkout config that inherits options from outside the checkout.--listFiles. The checkout boundary is now a post-check: every file the compiler read must be physically inside the checkout, and escaped inputs are reported before type errors.package.jsonandtsconfig*.json, because the command line does not report consulted manifests or failed resolution probes. The lockfile is deliberately not keyed:--listFilesreports dependency files at their versionednode_modules/.pnpm/<pkg>@<version>/paths (all 3,877 dependency inputs oftsconfig.core.json), so a dependency change already changes the inputs, and lockfile-only edits keep hitting the CI build-all cache.diagnostics: "declarations", sometimes a historical compiler) keep the API path unchanged.Behavior changes (intentional, pinned by tests)
node_modulesused to be hidden by the virtual filesystem; it now fails withDeclaration input escapes checkout: <path>. Test:fails closed when optional SDK relative imports reach a parent install.builds through a parent package link that resolves back inside the checkout.Test rewrites: receipts no longer list consulted
package.jsonfiles; the directory-alias test now proves that editing such a manifest re-keys the cache (cache miss). The cold-sibling build-order test sequences on the compiler subprocess instead of patchingProgram.prototype.emitToString.Impact
Full cache-off
pnpm build, one run each at load 36-45:write-unified-entry-dts2m 4.7s -> 1m 20.3s,tsdown-packages59.9 s -> 32.7 s, total 6m 27s -> 5m 24s. Single runs on a shared host; the per-step deltas are larger than the run-to-run noise we observed.Evidence
4d933d0, rebased on3256fe1): full builds of the PR head and of3256fe1. All 705 declaration files (dist,dist-runtime,packages/*/dist, extensions) are byte-identical. Across all 30,291dist/dist-runtimefiles, 9 differ, all build identity: stamps,build-info.json, the commit in help text and its signature, step cache-input hashes (which hash the changed scripts), and the Control UI service worker.test/scriptspass (254 passed, 5 skipped), includingnative-declaration-boundary,tsdown-declaration-resolution,native-declaration-subprocess,declaration-stageandtsdown-config.