Skip to content

improve: speed up cold declaration builds with spare memory - #149592

Merged
steipete merged 1 commit into
mainfrom
codex/perf-staged-declarations-r12
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-staged-declarations-r12

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cold unified declaration generation compiles its six independently staged groups serially, even when CPU and available memory can support two compiler processes. The same declaration owner already permits the two SDK groups to overlap.

User Impact

On the measured six-group declaration miss, average wall time fell from 207.53s to 133.70s on Node 24 (-35.57%) and 206.40s to 130.19s on Node 26 (-36.92%). Every one of the six adjacent baseline/candidate pairs improved wall time.

This trades resources for latency: average unit CPU increased 14.45% / 13.12%, sampled summed peak RSS increased 65.02% / 64.77%, and cgroup peak increased 66.83% / 61.87% on Node 24 / 26. These are declaration-stage measurements, not a whole-build or Gateway speedup claim.

Why This Change Was Made

Generalize the existing staged-declaration admission helper to canonical, distinct declaration groups. The existing executor still admits at most two nonempty, single-compiler private stages, preserves FIFO scheduling, joins all work before publication, and retains failure settlement, input validation and cache ownership.

Admission uses the two largest compiler heap budgets plus existing per-child native headroom. With the default 12 GiB heaps, it requires 25.5 GiB of known available capacity and at least two CPUs. Insufficient or unresolved capacity remains serial. No new configuration, heap override or cache policy is introduced.

Evidence

  • Existing owner tests extended for six unequal heaps, exact capacity boundaries, duplicate/unknown groups, queued-work suppression on failure and complete joins before publication.
  • Baseline regression: two intended admission failures; candidate 231 tests passed across three files.
  • Scripts type check and scoped production lint passed.
  • Fresh independent source review: no P0–P2 findings; documentation clause reviewed separately.
  • Formatting passed for all five files; docs MDX sanity passed.
  • Targeted root-test type check and two-file type-aware test lint passed (zero warnings/errors).
  • Exact-head hosted CI 35046581005 passed, including openclaw/ci-gate and its artifact build.
  • Candidate normal-build integration passed at published head 631898047319e5b7e80827fe801510d79cfe87ac: normal pnpm build, Node 26.8.2 on Linux/WSL, default heaps/profile, 306.316s. All six unified declaration groups and both SDK groups compiled on cache misses, with at most two compiler processes. SDK export, runtime postbuild and UI build checks passed; all children joined, zero OOM, source/tool pins unchanged. Initial resource refusals were retained; the unchanged original floors were met before launch. No remote lease was created. This closes the normal-build integration requests in the review; it is not a paired whole-build timing comparison. Receipt SHA-256: 52e80ffff2aeef8e87d6c2f0b9549da03e67335ffa2509add0c3de40da483577.
Fixed measurement protocol and all twelve results

Fixed measurement protocol

Pinned base 8384aaf0517c62c097cf39658b75db8fe9f6bedd, Node 24.19.0 and 26.8.2, native Linux under WSL. Four separate correctness captures precede twelve timing arms: Node 24 BCCBBC, Node 26 CBBCCB. Each arm restores the same declaration inputs and retained SDK cache, then invalidates the same six non-SDK groups. Default compiler heaps remain unchanged.

All sixteen runs passed complete declaration output and consumed-input parity (paths, bytes, modes and links; only the volatile cache stamp signature excluded). Every timing arm passed process identity, complete child settlement, source/tool stability and zero-OOM checks. No measured workload was retried or excluded.

Eight prelaunch resource refusals were retained before arms 03–06. No workload started on those attempts. The unchanged manifests and original resource floors were resubmitted after capacity recovered. A 19-minute scheduling gap before arm 06 also contained separate correctness checks, which joined before timing resumed. Slower candidate arms 06 (145.29s) and 07 (140.77s) remain in every aggregate.

Arm Node Variant Wall s Unit CPU s Sampled peak RSS GiB Cgroup peak GiB
1 24.19.0 Baseline 213.009 373.798 5.650 5.581
2 24.19.0 Candidate 128.586 414.567 9.587 9.518
3 24.19.0 Candidate 127.232 398.589 9.480 9.403
4 24.19.0 Baseline 203.221 350.996 5.833 5.773
5 24.19.0 Baseline 206.364 356.025 5.813 5.776
6 24.19.0 Candidate 145.294 423.818 9.475 9.658
7 26.8.2 Candidate 140.768 426.849 9.443 9.324
8 26.8.2 Baseline 210.706 360.740 5.810 6.056
9 26.8.2 Baseline 205.448 347.508 5.858 5.773
10 26.8.2 Candidate 124.240 383.674 9.701 9.572
11 26.8.2 Candidate 125.567 379.298 9.707 9.595
12 26.8.2 Baseline 203.042 343.572 5.843 5.771

The three-pair wall reductions range from 29.59–39.63% on Node 24 and 33.19–39.53% on Node 26. CPU and memory increased in all six pairs. Shared-host load and warm filesystem state can affect timings; this is a small repeated sample, not a statistical-significance claim. Unit CPU includes the observer. Summed RSS sampling can double-count shared pages or miss short peaks; cgroup memory includes page cache and is not RSS.

The complete retained analysis rehashes every saved validation and parity receipt. Analysis SHA-256: 2a95cd055c835c21e2c9daddea5113c68a9448b05241dbc22084f1e55b74cd7f; measured four-file patch SHA-256: 4b8104cc9cedd3bd64ea43b5dea08c2d3a9128d30ec5cb648ce7a24c5266d450. The documentation-only addition does not change the measured code. The published change was rebased onto main 6cf521932af06af674a90e2319ccbd6212261e5d; the five changed files and dependency manifests were unchanged at baseline, and range-diff, stable patch ID and all five resulting file hashes match the reviewed candidate.

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: S maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete marked this pull request as ready for review September 16, 2026 02:04
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 10:24 PM ET / September 16, 2026, 02:24 UTC (Revision 2).

ClawSweeper review

What this changes

Allow independent declaration compiler stages to run two at a time when CPU and available memory permit, with updated scheduling tests and build documentation.

Merge readiness

⛔ Blocked before merge - 2 items remain

The optimization remains useful: current main only overlaps the two SDK groups, and the earlier merged work does not cover the six-group build. No introduced correctness defect was found; the maintainer-protected PR should remain open.

Priority: P2
Reviewed head: 631898047319e5b7e80827fe801510d79cfe87ac

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with strong repeated stage measurements and no blocking code findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured Linux/WSL Node 24 and 26 runs exercise six real declaration compiler misses through the changed production owner and report faster completion with output parity and complete child settlement. This supports the stage-level claim; the separately pending normal full build remains an integration check.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured Linux/WSL Node 24 and 26 runs exercise six real declaration compiler misses through the changed production owner and report faster completion with output parity and complete child settlement. This supports the stage-level claim; the separately pending normal full build remains an integration check.
Evidence reviewed 7 items Current main still limits overlap to SDK groups: The fetched main revision requires exactly two canonical SDK groups, so six non-SDK misses still run serially. This establishes that the requested optimization remains absent.
Bounded admission and unchanged publication owner: The writer permits overlap only for nonempty misses with one compiler invocation each. Admission checks distinct canonical groups, two CPUs, known capacity, and the two largest heaps plus headroom. The existing executor joins all admitted children before validation, publication, and cache refresh.
Captured production-stage measurements: The supplied complete PR body records twelve timing arms and four correctness captures on native Linux under WSL with Node 24.19.0 and 26.8.2. Six non-SDK cache misses exercised the changed declaration owner; all captures reportedly preserved output and consumed-input parity. Average wall time decreased 35.57% and 36.92%, with increased CPU and memory explicitly disclosed. Captured context sourceRevision: adc428e4f4f98bf617ca7a8c15fe7c05caaf3dc1c7efaeccd28d6aabf1536788; retained analysis SHA-256: 2a95cd055c835c21e2c9daddea5113c68a9448b05241dbc22084f1e55b74cd7f. The body records patch-equivalence checks after rebasing onto the published base.
Findings None None.
Security None None.

How this fits together

OpenClaw’s build tooling turns TypeScript sources into packaged type declarations. Its declaration writer restores cached groups, compiles missing groups in private directories, and validates the complete output before publication.

flowchart TD
 A[TypeScript sources and cached declarations] --> B[Identify missing declaration groups]
 B --> C{CPU and memory sufficient?}
 C -->|Yes| D[At most two private compilers]
 C -->|No| E[Serial compilation]
 D --> F[Join children and validate outputs]
 E --> F
 F --> G[Publish declarations and refresh caches]
Loading

Before merge

  • Resolve merge risk (P1) - The recorded measurements cover declaration generation; integration through the candidate’s normal full build remains unverified in the captured evidence.
  • Complete next step (P2) - Complete and record the pending normal pnpm build at the published candidate head; the hosted ciArtifacts build does not exercise the six-group unified declaration stage.
Agent review details

Security

None.

PR surface

Tests +29, Docs 0, Other -1. Total +28 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 49 20 +29
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 14 15 -1
Total 5 64 36 +28

Review metrics

Metric Value Why it matters
Measured declaration-stage tradeoff Wall time −35.57% / −36.92%; CPU +14.45% / +13.12% The Node 24 / Node 26 measurements show lower latency at higher resource cost, without claiming a whole-build speedup.
Default overlap threshold 2 CPUs and 25.5 GiB known available capacity The existing 12 GiB compiler heaps plus per-child headroom keep constrained hosts on the serial path.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one declaration scheduler with conservative memory admission, private compiler stages, and complete validation before publication.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one declaration scheduler with conservative memory admission, private compiler stages, and complete validation before publication.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a correctness bug: current main deliberately serializes non-SDK groups, and the supplied repeated runs measure the resulting performance opportunity.

Is this the best way to solve the issue?

Yes. Generalizing admission in the existing writer avoids a competing scheduler and preserves serial fallback, failure settlement, and publication validation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 57956a7c8e80.

Labels

Label justifications:

  • P2: This is a bounded build-performance improvement with measured benefit and no urgent runtime regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured Linux/WSL Node 24 and 26 runs exercise six real declaration compiler misses through the changed production owner and report faster completion with output parity and complete child settlement. This supports the stage-level claim; the separately pending normal full build remains an integration check.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Linux/WSL Node 24 and 26 runs exercise six real declaration compiler misses through the changed production owner and report faster completion with output parity and complete child settlement. This supports the stage-level claim; the separately pending normal full build remains an integration check.

Evidence

What I checked:

  • Current main still limits overlap to SDK groups: The fetched main revision requires exactly two canonical SDK groups, so six non-SDK misses still run serially. This establishes that the requested optimization remains absent. (scripts/tsdown-build.mts:1196, 57956a7c8e80)
  • Bounded admission and unchanged publication owner: The writer permits overlap only for nonempty misses with one compiler invocation each. Admission checks distinct canonical groups, two CPUs, known capacity, and the two largest heaps plus headroom. The existing executor joins all admitted children before validation, publication, and cache refresh. (scripts/lib/tsdown-declaration-writer.mts:168, 631898047319)
  • Captured production-stage measurements: The supplied complete PR body records twelve timing arms and four correctness captures on native Linux under WSL with Node 24.19.0 and 26.8.2. Six non-SDK cache misses exercised the changed declaration owner; all captures reportedly preserved output and consumed-input parity. Average wall time decreased 35.57% and 36.92%, with increased CPU and memory explicitly disclosed. Captured context sourceRevision: adc428e4f4f98bf617ca7a8c15fe7c05caaf3dc1c7efaeccd28d6aabf1536788; retained analysis SHA-256: 2a95cd055c835c21e2c9daddea5113c68a9448b05241dbc22084f1e55b74cd7f. The body records patch-equivalence checks after rebasing onto the published base. (631898047319)
  • Normal-build integration remains explicitly pending: The captured PR body says candidate pnpm build is pending. Source confirms the full profile includes write-unified-entry-dts, whereas ciArtifacts skips that six-group stage and builds SDK declarations separately; the passing hosted artifact build therefore does not close this specific integration gap. (scripts/build-all.mts:202, 631898047319)
  • Meaningful scheduling regression coverage: Extended cases check unequal heap admission boundaries, reject duplicate or unknown groups, suppress queued work after spawn failure, preserve sibling errors, and require every successful stage to finish before publication. No tests or builds were executed during this read-only review. (test/scripts/declaration-stage.test.ts:34, 631898047319)
  • Related merged scheduling work and routing history: perf(build): overlap staged SDK compilers within memory capacity #145090 merged SDK-only overlap. Local file history connects that work and earlier declaration-cache changes to Peter Steinberger; GitHub commit metadata identifies steipete and supplies the scheduling patch against parent 2f48f72. Local blame/history expansion encountered unavailable-object fetch failures, so no introduction claim relies on that failed blame. (scripts/tsdown-build.mts:1943, 6cc8bb1a4b9e)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the published candidate’s normal pnpm build result, including the six-group declaration stage and subsequent SDK publication.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-16T02:12:34.545Z sha 6318980 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit a76f275 into main Sep 16, 2026
164 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant