JS fallback when Wasm is not supported#10118
Conversation
2f159f3 to
6ae070f
Compare
|
Hmmh, actually now I see What is Would it be ok if I deleted current
That would cover all the current use cases? |
|
Another option might be that I leave MAYBE_WASM2JS functionality alone as it currently is, and just add a new option |
|
Went ahead with that route from above - |
|
IIRC, @kripken added |
|
About the flags: The initial idea with |
I'm not opposed to that, but one major use case for that flag has been to allow debugging wasm2js easily - a single build that can be flipped between wasm and wasm2js, to see where anything diverges. I'd like to preserve that, but it's just for us devs so it's fine if it requires some fiddling. From the description it sounds like |
cdb8f2f to
7911c81
Compare
|
Went down the route of adding a new The existing |
Not sure if this is ready for review or not, based on that? |
sbc100
left a comment
There was a problem hiding this comment.
What are the use cases for this new build mode? Do we have users asking for this?
Downloading a fallback JS when Wasm is not supported. Yes, Unity. |
What devices do you support that don't have Wasm support? Also I wonder how many users needs this an whether it might be something that can instead be doing at the higher level (by the code that is load the emscripten code)? Given that is hopefully rare. We also don't really want to encourage the continued use of JS give that Wasm should universally supported these days right? |
It is not just about devices, but about software.
Love this statement! I wish it came from the JS team at Google and I could make a poster to hang on the wall :)
We do not currently see this to be the case, but once our analytics shows that JS is obsolete, we will be happy to drop it. |
Refactored this to move the JS fallback to a separate |
| x.send(null); | ||
| }); | ||
| } | ||
|
|
There was a problem hiding this comment.
Adding -s WASM=2 support to MINIMAL_RUNTIME started to make the minimal runtime loader shell quite cluttered, so migrated this whole thing to be dynamically generated instead from python.
Obviously I mean we don't want to see people compilomg C++ to JS.. since wasm should be everywhere. I'm pretty sure everyone on the v8 team would agree with that :) I'm really curious to know that browsers you are targeting that don't have wasm support. I know of one use case which I believe is ancient version of firefox OS run an old version of spider monkey. This seems like a really bad idea from a security POV and I'm not sure we want to be encouraging such deployments.
Obviously JS itself will not be obsolete for browsers that lack wasm... that should be a thing of the past soon I would hope. What do you think about my suggestion that people who want dual builds can build this at a higher level if they really need it? |
kripken
left a comment
There was a problem hiding this comment.
I think it might be cleaner to have WASM_AND_JS or such as a new flag, instead of WASM=2 having a special meaning.
Overall this lgtm, but I am curious to hear your thoughts on @sbc100's suggestion to do this at a higher level. In particular as I read this I wondered if we could have fewer changes to emcc.py and have a tool that is separate, that drives two emcc.py compilations and generates the "combined" build from that?
| (opts, hello_webgl2_sources, {'a.html': 1565, 'a.js': 5172, 'a.wasm': 11809}) # Compare how WebGL2 sizes stack up with WebGL 1 | ||
| (opts, hello_world_sources, {'a.html': 1205, 'a.js': 484, 'a.wasm': 176}), | ||
| (opts, hello_webgl_sources, {'a.html': 1335, 'a.js': 4663, 'a.wasm': 11809}), | ||
| (opts, hello_webgl2_sources, {'a.html': 1335, 'a.js': 5172, 'a.wasm': 11809}) # Compare how WebGL2 sizes stack up with WebGL 1 |
There was a problem hiding this comment.
what's the reason for this improvement?
There was a problem hiding this comment.
With dynamic loader generation, the binary() and script() functions are only included on demand. Although the .html sizes contain unminified JS until #9990 lands, so these numbers are not very meaningful until that.
We target a number of Webviews and other development/deployment ecosystems that do not necessarily have the latest and greatest tech with wasm. If you would like to really talk about this in detail, I can look at connecting you with our marketing and analytics side for more precise statistics percentages, after we have shipped upgraded dual wasm+js builds in the wild. (Currently for such ecosystems we are doing asm.js only builds without wasm support)
Build times are a major concern, and having to run a build twice for work that is already done by the toolchain "for free" would be technically silly.
A benefit of With a |
|
Regarding continued support for JS output: The webview/bespoke target/dev target arguments make sense to me. I guess it will take some time for my dream to come true here :) Regarding using WASM=2 vs a whole new options: I kind of agree with both side of the case. The existing options that take more the ON/OFF I do find very confusing. For example MAIN_MODULE=1 vs MAIN_MODULE=2 I find very non-ergonomic within the codebase and as a user. I think it would have been way nicer to have two options there: However, @juj points out its also annoying when one has options can can contradict each other. e.g the WASM option would make no sense in the presence of WASM_AND_JS. |
kripken
left a comment
There was a problem hiding this comment.
Good point about the orthogonality of the flags. So WASM=2 sounds good to me. lgtm with docs in settings.js.
|
@sbc100 I agree that the ergonomics are not great with flags like Perhaps a more ergonomic way could be to allow string names, so |
|
hi, sorry for english . version info: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.39.12 |
|
Can we make |
|
@VictorQueiroz If someone has an idea, a PR would be welcome of course. I don't have a simple one myself atm. But this should be easy to work around, I think, if you add some scoping, (function(WebAssembly) {
// Put all the emscripten output here.
// It is fine to do WebAssembly = ... here, and it will not affect the global scope.
})(WebAssembly);That will read |
I am not quite sure I understood the set of flags we have now. There are
WASM=0/1, which enables targeting to Wasm, or disables Wasm, and targets Wasm2JS unconditionally.WASM2JS=0/1, which seems to be the negation of WASM(?),MAYBE_WASM2JS=0/1, which had code to conditionally enable running with Wasm2JS, if a specialModule['doWasm2JS']boolean was enabled.However
MAYBE_WASM2JSdid not actually generate both JS and Wasm code, but either created Wasm if-s WASM=1(and running as JS would fail), or would create JS if-s WASM=0, (and running as Wasm would fail)This PR changes the meaning of
MAYBE_WASM2JSto mean "run as WebAssembly if support is present, otherwise run as JS fallback".That is, if building with
emcc tests\hello_world.c -o a.html -s MAYBE_WASM2JS=1. it will generate each ofa.html,a.jsanda.wasm, and pick to usea.wasmif Wasm is supported, otherwise it runs the Wasm2JS code ina.js.I think that makes
MAYBE_WASM2JSmore useful in practice.Also adds WASM2JS support to MINIMAL_RUNTIME.
A future change is to make
MAYBE_WASM2JS=1imply--separate-asm. That is, if running a build that has a JS fallback enabled, the VM should only download either the JS code or the Wasm code, but not both. But that's for later.