Engodev/improve compile time#298
Conversation
d84a746 to
b99befd
Compare
|
Thank you for looking into this! If I understand your results correctly, most of the improvement comes from updating The change to use parallelization and hence moving to a native build seems much more involved: we'd have to publish native versions for at least three, ideally four or five platforms, same as we already do for Wizer. That's not the end of the world for sure, but if we get most of the improvement without such an invasive change, we should consider not doing it. This is in part because we're planning on completely changing how we do bindings generation for StarlingMonkey, by adopting the new wit-dylib tool. At that point, everything done to ComponentizeJS as it is right now will become moot, so I think we shouldn't stay away from involved changes. |
|
Yeah that makes sense, I'll open another PR with only the I do think it's worth considering the CLI change as it does add a significant performance boost for little to no effort and it's an opt in feature so users aren't bothered with it. |
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.rstest/splicer.jsMakefilesrc/componentize.jstosrc/splicer.jsTL;DR
The two optimizations I introduced are:
wirm(previously known asorca_wasm) to the latest version and enabling theparallelfeature.spidermonkey-embedding-splicerto 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(Awirmfunction) and the hot path for it is this code right here:Module::parseis called multiple times during compilation and every time its called thecode_sectionscreation takes about 95% of the run time forModule::parsewhich was around 350ms for me. As the great guys over atwirmalready did fantastic work by giving the option to parallelize this code the only thing left to do was to enable the featureparallelbut because WASM doesn't support multi threading yet just enabling theparallelfeature forwirmdoesn't do anything.So to get around that I added a new option
--splicer-binthat will use thespidermonkey-embedding-splicerCLI 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
WITworld:Running

jcoon it took 4.5s on average.Running

componentize-jswith thewirmup to date took 1.5s on average.Running

componentize-jswith thewirmup 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-binwhich will include compiling