Skip to content
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

[discussion] JIT dynCall functions #12141

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

[discussion] JIT dynCall functions #12141

wants to merge 25 commits into from

Conversation

kripken
Copy link
Member

@kripken kripken commented Sep 9, 2020

This is probably not a good idea, but opening for discussion.

When we need to do a dynCall to something with an illegal type, we currently use a dynCall in the wasm, which means we have to generate those at compile time. Instead, this PR lets us JIT those dynCalls on demand. We create a tiny wasm binary that imports the table and that exports the new dynCall, cache that, and call it.

This would have the benefit of not creating any dynCalls at all during compile time which would help WebAssembly/binaryen#3043. However, it takes around 1-2ms to JIT each dynCall it seems, so potentially this is noticeably slow in a big project, and it probably uses more memory (but I actually didn't see anything obvious in my testing there).

This also can't quite remove all dynCalls. For asyncify we need to instrument the dynCalls for asyncify at compile time, so a JIT version is not good enough. And for wasm2js we'd need some more help as right now we go through a dynCall that is properly legalized, including calling setTempRet0 etc., so we'd need to add some mechanism to set the high bits inside the wasm2js module (which doesn't exist atm).

@kripken kripken requested a review from sbc100 September 9, 2020 21:21
@sbc100
Copy link
Collaborator

sbc100 commented Sep 9, 2020

I wonder if we could have hybrid approach of creating a single wrapper module containing the dynCalls ahead of time?

We could write the module out as part of wasm-emscripten-finalize --metadata-only (or whatever that ends up being called)?

If course this only works if we know at compile time which possible dynCalls we will need, but we currently rely on that today.

@kripken
Copy link
Member Author

kripken commented Sep 9, 2020

I wonder if we could have hybrid approach of creating a single wrapper module containing the dynCalls ahead of time?

Very interesting... yes, I think that would be practical, and better than this PR.

The question is whether we think it's worth it, I guess. The main downside is adding complexity. In particular for wasm2js it would be tricky to get right - it currently assumes a single wasm module that is replaced by a single JS "module" (that's a problem for both ideas).

I am leaning towards these solutions not being worth it, and -O0 builds will still do some work after link, while only -O0 -s WASM_BIGINT will not. I think we can get the docs and error messages clear enough. But I am sad there isn't a nice way without complexity to achieve -O0...

Base automatically changed from master to main March 8, 2021 23:49
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Apr 16, 2022
@stale stale bot closed this Jul 31, 2022
@sbc100
Copy link
Collaborator

sbc100 commented Aug 1, 2022

Looks like this idea resurfaced in #17328

@tlively
Copy link
Member

tlively commented Aug 3, 2022

Now that we have multi-memory in Binaryen, we can reintroduce wasm-merge. With wasm-merge, generating separate wrapper modules becomes nicer because in the optimizing path we can merge them into the main module so that the wrappers are included in optimizations.

cc @ashleynh

@tlively tlively reopened this Aug 3, 2022
@stale stale bot removed wontfix labels Aug 3, 2022
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.

3 participants