Skip to content

perf(wasm-sdk): speed up release WASM optimization - #5147

Merged
ktechmidas merged 4 commits into
v4.2-devfrom
fix/ci-npm-binaryen-cpu-budget-20260928
Sep 28, 2026
Merged

ktechmidas merged 4 commits into
v4.2-devfrom
fix/ci-npm-binaryen-cpu-budget-20260928

Conversation

@ktechmidas

@ktechmidas ktechmidas commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

The NPM release build is dominated by Binaryen. In the baseline job, yarn build took 87m24s, of which wasm-sdk optimization took 70m41s. There were two causes:

  • Binaryen sizes its thread pool from the host CPU count. Inside a Docker CPU quota that oversubscribes; profiling found 77% of sampled CPU in kernel futex spin locks.
  • The full recipe in build-wasm.sh ran -Oz four times with --converge, --flatten/--rereloop and extra passes. It first probed 14 optional flags by optimizing the entire module once per flag.

This consolidates #5152 into this PR.

What was done?

  • Default Binaryen to four threads in the NPM release build step (BINARYEN_CORES, which a runner-provided value overrides). Cargo's job budget is unchanged. The step logs the thread count and times yarn build.
  • One standard -Oz pass for full optimization, keeping producer stripping and the same enabled WASM features. Minimal (-O2), no-optimization and the wasm-sdk optimized.wasm copy are unchanged.

No Rust source, dependency, Cargo profile or binding changes.

Measurements (from #5152)

Same 47,166,333-byte pre-optimization wasm-sdk module, Binaryen 121, 20-CPU/32 GiB container:

Optimizer Wall time Output bytes gzip-9 bytes
Original recipe, host-sized pool ~62m 23,682,944 8,175,680
Original recipe, 4 threads 16m41s 23,682,944 (byte-identical) 8,175,680
Single -Oz, 4 threads 2m18s 24,164,835 8,203,934

The single pass costs +2.0% raw / +0.35% gzip (~28 KB compressed). The optional -tnh (traps-never-happen) pass is no longer applied. A cold full yarn build on the self-hosted runner completed in 8m01s (single run, build stage only). The previous build's 441 SDK Node tests passed on both optimizer outputs, with identical WASM imports/exports.

How Has This Been Tested?

  • actionlint, shellcheck and the existing .github/scripts/tests suite pass.
  • The four applicable contract tests from perf(wasm-sdk): eliminate repeated release optimizer passes #5152 pass against the final build-wasm.sh: optimized.wasm copy, minimal/none modes, missing wasm-opt, and optimizer failure propagation.
  • Pending: the NPM runner-validation build on this PR is the first CI run of the single -Oz pass. Four threads was measured with the original recipe; it has not been re-tuned for the single pass.

Breaking Changes

None. Released WASM bytes change (slightly larger) because of the optimizer recipe.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 2806459

  • Bots — coderabbitai not yet · thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — address PastaPastaPasta left a review thread unresolved, then post /self-reviewed
  • Within your 5 open PRs
  • Build running
  • Approvals
    • files with no dedicated owner (.github/actions/npm-release-build/action.yaml, packages/scripts/build-wasm.sh) — QuantumExplorer or shumkov

When every box is checked the PR Hygiene check passes and this can merge.

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 7a99ae27-d88b-4696-8ffc-e3a7c8898e51

📥 Commits

Reviewing files that changed from the base of the PR and between d22f8ab and 2806459.

📒 Files selected for processing (2)
  • .github/actions/npm-release-build/action.yaml
  • packages/scripts/build-wasm.sh
 _________________________________
< My bunny whiskers are tingling. >
 ---------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 28, 2026
@thepastaclaw

thepastaclaw commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 2806459. Normal review starts when eligible; priority review starts as soon as a slot is available.

SPEC.loader.exec_module(MODULE)


class NpmBuildBudgetTests(unittest.TestCase):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this; we don't need tests for a simple build script

PastaPastaPasta and others added 3 commits September 28, 2026 14:51
Replace the Python launcher and its tests with a few lines in the
existing build step: cap BINARYEN_CORES at min(nproc, cgroup v2
cpu.max quota), keep any runner-provided value, log it, and time
`yarn build` with the exit status preserved.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Four optimizer threads were measured ~3x faster than a host-sized pool
with byte-identical output, which makes cgroup quota detection
unnecessary. A runner-provided BINARYEN_CORES still takes precedence.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The full-optimization recipe ran -Oz four times with --converge,
--flatten/--rereloop and extra passes, and first probed 14 optional
flags by optimizing the entire module once per flag. On wasm-sdk this
took over an hour with a host-sized thread pool (16m41s at four
threads). One standard -Oz pass with the same features and producer
stripping takes 2m18s for +2.0% raw / +0.35% gzip size.

Minimal (-O2) and no-optimization builds and the wasm-sdk
optimized.wasm copy are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@PastaPastaPasta PastaPastaPasta changed the title ci(wasm-sdk): bound optimizer threads independently of compilation perf(wasm-sdk): speed up release WASM optimization Sep 28, 2026
@PastaPastaPasta
PastaPastaPasta marked this pull request as ready for review September 28, 2026 20:13
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 28, 2026

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ktechmidas
ktechmidas merged commit a0a7b3f into v4.2-dev Sep 28, 2026
62 of 64 checks passed
@ktechmidas
ktechmidas deleted the fix/ci-npm-binaryen-cpu-budget-20260928 branch September 28, 2026 20:14
PastaPastaPasta added a commit that referenced this pull request Sep 28, 2026
Pick up #5156 (validate runner candidates using full commit statuses),
#5153 and #5147.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants