Engodev/improve compile time #298
Open
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.
The goal of this PR is to decrease the time it takes to compile a JS file into a WASM component.
AI disclaimer
I used AI in the creation of this PR. Specifically the Cursor composer (Claude-4.5-sonnet and GPT-5) for:
crates/spidermonkey-embedding-splicer/src/bin/splicer.rs
test/splicer.js
Makefile
src/componentize.js
tosrc/splicer.js
TL;DR
The two optimizations I introduced are:
wirm
(previously known asorca_wasm
) to the latest version and enabling theparallel
feature.spidermonkey-embedding-splicer
to take advantage of the multi threading capabilities ofwirm
.Research
I found that most of the time for compiling the JS code into WASM is being used in
Module::parse
(Awirm
function) and the hot path for it is this code right here:Module::parse
is called multiple times during compilation and every time its called thecode_sections
creation takes about 95% of the run time forModule::parse
which was around 350ms for me. As the great guys over atwirm
already did fantastic work by giving the option to parallelize this code the only thing left to do was to enable the featureparallel
but because WASM doesn't support multi threading yet just enabling theparallel
feature forwirm
doesn't do anything.So to get around that I added a new option
--splicer-bin
that will use thespidermonkey-embedding-splicer
CLI instead of the compiled WASM module so it can take advantage of multi threading and that made it possible to go from ~4.5s compilation time to ~750ms compilation time.Performance Numbers
All testing took place on a Apple M4 Pro with 48GB of RAM.
I used a simple JS file for my testing:
With a simple
WIT
world:Running

jco
on it took 4.5s on average.Running

componentize-js
with thewirm
up to date took 1.5s on average.Running

componentize-js
with thewirm
up to date and leveraging the CLI splicer for multithreading took 750ms on average.Question
This PR right now doesn't have anything in the README on
--splicer-bin
, I wanted to know first what is the approach you would want to take regarding the packaging of the CLI splicer, right now it's not published and in the npm pacakge there is only the WASM module. I thought of two ways we can tackle user consumption but if you have another approach I'm happy to implement :)--splicer-bin
which will include compiling