Repository navigation
build: faster build (native wasm-opt, cached wasm-opt, parallel tsdown) and CI - #142
Merged
Merged
Conversation
⏱️ Benchmark resultsComparing head Note No performance regressions detected.
Node v26.13.0: times
Chrome 156: times
Firefox 158: times
Δ time is the median of the per-round head/base ratios (lower is better). RegExp is the time of the equivalent native Workflow run · updated for |
The `binaryen` npm package is an emscripten (JS) build of wasm-opt and runs on one thread: ~8.3s of a ~9s rebuild. bin/wasm-opt.sh now prefers a native wasm-opt with the same version as the npm package from PATH (~0.6s, same output byte for byte) and falls back to the npm package. - bin/install-binaryen.sh downloads the matching binaryen release and checks its sha256; both workflows put it in PATH - the release workflow checks that the native and the npm wasm-opt give the same wasm - bin/build.sh prints the time of each step and writes them to $BUILD_TIMINGS; the benchmark report shows them Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The native and the npm wasm-opt gave the same wasm on Linux x86_64 in CI. bin/wasm-opt.sh only uses a native wasm-opt with the same version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bin/install.sh installs it in target/binaryen and bin/wasm-opt.sh looks for it there after PATH, so local builds also use the native wasm-opt. The workflows already run `setup`, so their own install step goes away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bin/wasm-opt.sh keeps the last output in target/wasm-opt, keyed by the input, the binaryen version and the script itself. A rebuild that does not change the Rust code skips wasm-opt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tsdown only reads js/ and never bundles lib/rregex.wasm, so both steps run in parallel. Each step still reports its own time; the total is the wall time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `test:rs` builds the crate in the test profile before the build. It now runs in the `test_rs` job, next to the build; `publish` still needs it. - The cargo cache key was only Cargo.lock: a new Rust on the runner restored a stale target/ and an exact hit never saved a new one. Swatinem/rust-cache adds the rustc version to the key and keeps only the dependencies. The release build and the benchmark share the key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2fd
force-pushed
the
2fd/build-performance
branch
from
November 1, 2026 04:53
e3baeac to
a35e502
Compare
core (cjs), commonjs and cf export exactly what core exports, so tsdown generated the same .d.ts four times. bin/build.sh now copies core.d.mts to the other three; lib/ is byte for byte the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…their own job - rust-cache does not keep target/binaryen, so `setup` downloaded it on every run; actions/cache keeps it, keyed by the binaryen version. - bin/check-regex-deps.sh asks crates.io for publish dates before the build. It now runs in the `check_deps` job, next to the build; `publish` needs it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n available `cargo install` compiles each one in ~1-2 min; cargo-binstall downloads the prebuilt binary. Without it, bin/install.sh still uses `cargo install`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
wasm-optfrom thebinaryennpm package is an emscripten (JS) build that runs on one thread. On a clean local build it took 8.3s out of ~17s. On a JS-only rebuild it took 8.3s out of ~9s. In CI, the Rust tests and a stale cargo cache were also on the critical path of thebuildjob.What
Build (
bin/)wasm-opt.shuses a nativewasm-optwhen its version matches thebinaryennpm package (version_132). It looks inPATHfirst, then intarget/binaryen. If there is none, it uses the npm package. It skipsnode_modules/*, becausepnpm runandnode --runputnode_modules/.binfirst inPATH.WASM_OPT_NPM=1forces the npm package.wasm-opt.shkeeps the last output intarget/wasm-opt. The cache key is the input, the binaryen version and the script itself, so a rebuild without Rust changes skipswasm-opt.install-binaryen.sh <dir>downloads the matching binaryen GitHub release for the current OS and arch and checks its.sha256.install.sh(pnpm setup) uses it to install intotarget/binaryen, so local builds and CI get the native binary.tsdown.config.tsno longer generates the.d.tsfiles of core (cjs), commonjs and cf. They export exactly what core exports, sobuild.shcopiescore.d.mtsto them. tsdown went from 6 to 3 declaration builds, andlib/is identical byte for byte.install.shusescargo binstall(prebuilt binaries) for wasm-bindgen-cli and wasm-pack when it is installed.build.shrunstsdownin parallel withwasm-opt, because tsdown only readsjs/and never bundleslib/rregex.wasm. It prints the time of each step and the total. WhenBUILD_TIMINGS=<file>is set, it also writes them as JSON.CI
test:rsmoved to its own job,test_rs, which runs in parallel withbuild.publishstill needs it.actions/cacheis replaced bySwatinem/rust-cache@v2. The old cache key was onlyCargo.lock, so a new Rust on the runner restored a staletarget/, and an exact cache hit never saved a new one. The rust-cache key includes the rustc version. The releasebuildjob and the benchmark shareshared-key: release.target/binaryenis cached withactions/cache, keyed by the binaryen version, because rust-cache does not keep it.check-regex-deps.shmoved to its own job,check_deps, which runs in parallel withbuild.publishstill needs it.bench-compare.mjs --build-time).Verification (local, macOS arm64, 14 cores)
wasm-opt -O …bin/build.sh, cargo warmbin/build.sh, no Rust changeslib/identical (cmp)WASM_OPT_NPM=1.wasm-optcache works on a hit, on a miss, and whenwasm-optfails: a failure does not poison the cache.lib/rregex.wasmdoes not exist yet.install.shinstalls binaryen once, verifies the sha256, and skips the download when binaryen is already there.A first CI run had a
checking wasm-optstep that ran the npmwasm-opton the same input. The output was identical withcmpon Linux x86_64. I removed the step afterwards because it took ~15s on the build job.🤖 Generated with Claude Code