Skip to content

Reuse Ruby builds when static gem extensions are unchanged - #669

Draft
ledsun wants to merge 2 commits into
ruby:mainfrom
ledsun:cache-static-gem-extensions
Draft

ledsun wants to merge 2 commits into
ruby:mainfrom
ledsun:cache-static-gem-extensions

Conversation

@ledsun

@ledsun ledsun commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Note: This PR currently also includes the changes from #671.

rake npm:ruby-head-wasm-wasi currently forces a Ruby rebuild on every run, repeating linking and Asyncify even when the statically linked gem extensions have not changed.

The motivation is to improve the local development experience by making repeated Rake builds faster. When working on JavaScript bindings or packaged Ruby code, developers can rerun the packaging task without waiting for unnecessary Ruby linking and Asyncify, shortening the feedback loop.

Measured end-to-end rake npm:ruby-head-wasm-wasi times on a local development machine, with dependencies and Ruby object files already present and BINARYEN_CORES=1 for both runs:

Build path Elapsed time
Rebuild Ruby, including linking and Asyncify 3m52.19s
Reuse Ruby with unchanged gem extensions 46.78s

The repeated build was about 5x faster, reducing elapsed time by 80% and saving about 3m05s per run. These are single-run local measurements, not CI benchmarks.

This benefit applies to repeated local builds. This change does not speed up CI builds.

Add an ExtensionCache that uses the existing extension cache_key methods and stores the input hash beside the Ruby archive. Reuse the archive when the hash matches, and remove the unconditional --remake from npm packaging. Explicit --remake, --reconfigure, and --clean still force a build.

Invalidate the previous record before building, and save a new record only after a successful build whose extension inputs stayed unchanged. Existing archives with extensions but no record are rebuilt once; archives without extra extensions retain their existing reuse behavior. Ruby source, compiler, and build-setting changes still require a manual rebuild.

Upstream rb-sys added arm-linux-musl to the platform list fetched by CI.
Treat 32-bit ARM Linux as unsupported by the build tools, following the
existing arm-linux exclusion, and exclude the musl variant as well.
@ledsun
ledsun force-pushed the cache-static-gem-extensions branch from 2082c73 to afdb4a0 Compare October 19, 2026 02:10

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant