Conversation
2484a29 to
b84c9bd
Compare
834c3bd to
aa256bb
Compare
|
Hm.. it looks like more work is requires to make the binaryen API bigint friendly. @kripken did you take a look at this in the past? |
|
Hmm, no, I don't recall doing that. More generally, my hope is we can move binaryen.js to embind so stuff like this is handled automatically. |
It seems like there are places where the API uses 64-bit stuff and is not expecting it to simply use bigints |
991158b to
8d03d35
Compare
|
I decided to look into the changes needed to the JS API.. WDYT? |
kripken
left a comment
There was a problem hiding this comment.
Changes make sense to me, but they are breaking, so please update the changelog.
This flag has been enabled by default in emscripten for a while now so I don't think we need this here anymore. The main user-visible effect of this change is that it makes the `module.i64.const` JS method now simply take a single bigint rather than a pair numbers.
|
Oops, sorry, I didn't realize that would auto-land. Will add a Changelog entry now. |
|
@sbc100 How do I use this? |
|
@guest271314 exactly is the problem you are trying to solve? Are you building binaryen with |
|
Oh I see, it looks like maybe its not possible to use |
I didn't build Binaryen. I have just been using the prebuilt executables from Releases. I just thought The source code that creates the WASM is in Zig. I'm just trying to get the WASM produced by Zig, that works as WASM, to JavaScript, by any means necessary - and still work. |
|
Hmm.. I'm a little confused about that the problem is that you are facing. The the prebuilt binaries for binaryen do not use wasm2js right (i.e. https://github.com/WebAssembly/binaryen/releases/download/version_128/binaryen-version_128-node.tar.gz contains both js and wasm files). So I guess you are not referring here to running binaryen itself under wasm (i.e. not really related to this issue) but using wasm2js to convert a Wasm module to JS? What is the specific wasm2js issue you are running into? You would prefer that the resulting JS did use BigInt for i64? |
Yes. In JavaScript The output of |
|
Ok, so this is unrelated to this PR I believe, and the behaviour of wasm2js has simply never worked with bigint/i64. @kripken, correct me if I'm wrong by I think the solution that emscripten depends on here is to first always run the @kripken, how hard would it be to add i64/bigint support for wasm2js? I guess one argument against doing that is the its hard to imagine a target that is new enough to support BitInt but old enough to now support WebAssembly? @guest271314 what engine are you targetting that has BigInt support in JS but not WebAssembly support? |
|
Yes, legalizing the API is a way to fix this. Pairs of i32s can then be combined on the JS side to a BigInt (and for return values there is Yes, we could support BigInts in wasm2js, but its focus is really on older browsers/VMs that lack wasm support entirely, and those places likely don't have BigInts or other modern JS features. So we have not been adding new feature support there. |
|
@sbc100 I tried I guess my idea about "Old" browser, at this point, could be the Chromium or Nightly TOT build from yesterday. I only use snapshots and fetch the lastest CHromium and Nightly every day or so. I'm tryint to port code from Zig to JavaScript, using WASM as the bridge. I'm trying to do that by any means necessary. |
That would be useful. |
What is the practical motivation there? I mean, why use pure JS rather than JS+wasm, in "new" browsers that have wasm? |
For me, that JavaScript, including JavaScript in the browser, is on par with Rust, C++, C, Go, Python, etc. as to programming language capabilties. If it can be done in C++, it can be done in JavaScript. To see how far I can go with browser capabilities, and JavaScript capabilties, in the language itself, without importing a That was my motivation for creating a WebTransport server in the browser. |
|
I see, interesting. In general we have prioritized allowing code to work - we want our users to be able to ship code that runs - rather than other considerations like you mention. We also focus a lot on performance, but that reaches the same conclusion here, since using wasm is generally faster than JS. I wouldn't be opposed to a patch that improves wasm2js here, but this is not something that I would work on myself. |
I don't think so. The Same algorithm, run 10 times for each script/executable/execution by I'm gonna have to do a WASM-only table. So far I've compiled the same algorithm to WASM from JavaScript, AssemblyScript, C, C++, Go, Rust, Zig - and compare those numbers to the JavaScript engines, runtimes, interpreters.
Static Hermes and QuickJS smoke AssemblyScript and Javy. There is no singular "wasm", nor a singular "JS". There are dozens of JavaScript engines, runtimes, interpreters. For example, Facebook (Meta) Static Hermes engine compiles JavaScript to native executable Ahead of Time, can emit C, and be compiled to WASM with WASI-SDK, or Emscripten. QuickJS is all over the place, Including Javy. QuickJS (NG) proper is faster than Javy compiled to WASM. Google's V8 There's potential hazard in relying on only the tests and claims of the claimants of anything themselves. I prefer to vet, everybody. Similarly, within the span of a decade or so "wasm" is all over the place; servers, WASI P! to WASI P3 in a short span. Great! Thanks for your consideration. |
|
There are certainly exceptions - you can make a microbenchmark where JS is faster than C. But, here we are comparing wasm to wasm-compiled-to-JS (wasm2js), which is not ordinary JS. It won't have JS objects in the compiled code, in particular, and not benefit from JS's GC there. On that comparison, it is extremely rare to have JS be faster than wasm in my experience. I can't remember a single production use case where wasm2js made things faster for a user. |
I was specifically replying to the idea that WASM is faster than JavaScript in general. The first question is which JavaScript engine or runtime or interpreter A list of JavaScript engines, runtimes, interpreters executing exactly what in what form versus which WebAssembly runtime executing exactly what in what form. The details can be tedious when we consider the number of JavaScript engines, runtimes, interpreters; and conversely the various WebAssembly implementations, modules versus components, WASI P1 cf. WASI PN. Technically ECMA-262 doesn't have I/O specified, so the question might arise about exactly how the result are even read. For the So, I'm thinking about the general functionality of converting one code base from one programming language to another as a baked in feature of WebAssembly. I don't think "performance" will be an issue. But we can test and verify to make sure - if we can get |
|
@kripken Perhaps think: speak.js. Capability, in JavaScript. Years later, browsers still don't ship a builtin TTS or STT engine for Web Speech API. They got room for "AI" stuff, though... |
|
@guest271314 Fair enough, those are interesting questions. It just happens that those motivations aren't shared by the majority of our users. Most of them focus on shipping code to the Web, where browser engines run it, and where wasm runs very fast. wasm2js hasn't been a priority for that reason. And even off the Web, people usually ship in Node.js - where, again, wasm is fast - or in a dedicated wasm VM. |
|
@kripken I got this working from |

This flag has been enabled by default in emscripten for a while now so I don't think we need this here anymore.
Also remove the
-Wno-experimentalflag which is no longer needed for-sMEMORY64.Also remove
-sMODULARIZEwhich is implied by-sEXPORT_ES6.