-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Meta-DCE for JS+WASM #5919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meta-DCE for JS+WASM #5919
Conversation
…more exports creep in
Personally, I would like this for |
Yeah, I think it's reasonable to do this in But @nmrugg I'm curious where you saw it produce much faster code? I wouldn't expect that to be noticeable. |
In Stockfish.js I see a big difference. With I can post details if you want to investigate. |
Perhaps I should note that those numbers are for asm.js. When compiled to WASM, |
Got it, thanks. Makes sense to me now, I misunderstood what you wrote before. |
Feedback here and offline has been positive, merging. |
This starts to use binaryen's
wasm-metadce
tool in-Os
and-Oz
, which lets us remove unused code along the boundary of wasm and JS. That is, it can remove things which doing DCE separately on each can't, like cycles between the two worlds.For example, if wasm imported a JS function, then if the wasm optimizer manages to remove all uses of it, this lets us remove it not just from wasm but also from the JS side too. And the same works the other way as well.
So far, in
-Os
this shrinks hello world's.js
by 3% and.wasm
by 18%. This is less effective on large programs, since the removable runtime overhead is smaller - e.g. when using C++ iostreams, it shrinks by 7% / 1%. But where this really shines is on small programs like the testcase in #5836, that just do a little pure computation and don't need a runtime at all: this shrinks that.js
by 5% and the.wasm
by 84% (mostly thanks to getting rid of malloc/free!). The absolute numbers are interesting for the wasm, it goes from 10,729 bytes to just 1,740, which is getting us most of the way to emitting a really minimal wasm for such inputs. This reason this doesn't get us all the way is because:On the other hand, this does increase compile times noticeably, mostly on tiny files: 47% for hello world and 23% for C++ iostreams. That's why I think this makes sense to do in
-Os
and-Oz
, but not other modes.