Top
Best
New

Posted by eqrion 12 hours ago

Saying goodbye to asm.js(spidermonkey.dev)
294 points | 128 commentspage 2
hollowturtle 7 hours ago|
Isn't Asm.js better just for the fact that I can call web apis directly without shims? Or moving data in and out? I'd love to commit totally to webassembly but still seems very limited, am I wrong?
aabhay 7 hours ago||
Wasm can also call web apis directly. The overhead you hear about is in translating complex types like nested dicts etc between formats. But wasm runs inside the js runtime
0x457 7 hours ago||
Depends on what do you mean about by web apis. Fetch API for example is not part of asm.js subset of JavaScript. You going to need a javascript shim on both cases. However, like the siblings comment says: overhead comes from conversion between big structures.
stkdump 10 hours ago||
There goes my plan to use js code generation at runtime to make my algorithms faster. Doing this with wasm will be much harder.
eqrion 9 hours ago||
Generating wasm code at runtime is pretty easy (I'd imagine easier than generating valid asm.js code). We have a little library for our tests that handles a lot of it: https://searchfox.org/firefox-main/source/js/src/jit-test/li...
giancarlostoro 10 hours ago|||
There's still AssemblyScript? It might meet your requirements, unless I'm misunderstanding you or the features of it.

https://www.assemblyscript.org/

flohofwoe 10 hours ago|||
Just try the asm.js subset and see how it performs for you, I remember that even without the special asm.js support in browsers Emscripten output performance was surprisingly good
cogman10 9 hours ago||
In fact, I think it was only firefox that made a special JIT route. Chrome moved optimizations into the regular JIT.
titzer 10 hours ago|||
It will still work. asm.js is just regular JavaScript code, after all. It just won't parse/run as fast as custom pipeline for asm.js. My guess is that you will not notice much difference unless you have a really huge application.
koolala 10 hours ago||
There are some WAT compilers that are small and fast for running in the browser.
koolala 11 hours ago||
Never saw those monkey prints before

https://monkeyink.com/ink/blog/archives/2016/08/_this_is_a_f...

"The image is a collage of antique open source art reflecting the open source code."

dblohm7 8 hours ago|
The SpiderMonkey team always had t-shirts made up of these.
EdwardDiego 9 hours ago||
We'll drink again in Valhalla (not the JDK project, the one with much carousing).
karel-3d 4 hours ago||
What I liked about asm.js is that it's "just" javascript and you don't need any special way to load them, while with wasm you have the wasm file which you need to load on the side, which is a bit clunkier. But eh it's a tiny thing
claytongulick 8 hours ago||
It would have been nice if they had mentioned Luke Wagner, who's idea it all was and who created the first implementation, as well as one of the main driving forces behind wasm.
unconed 10 hours ago||
Asm.js was never needed as a legacy mechanism, as it was just a compilation target for native code. There was nothing that it needed to remain backwards compatible with, all asm.js code was new code.

https://acko.net/blog/on-asmjs/

pornel 6 hours ago|
OTOH asm.js can be retired now thanks to being backwards compatible with plain JS.

It allowed it to be an experiment that could have been quickly rolled out without a risk of forever lingering as a back-compat requirement for browsers.

theultdev 11 hours ago||
Sad day. I have a sha256 hasher in asm.js that's faster than any wasm solution.
bvisness 9 hours ago||
In SpiderMonkey, asm.js code has been compiled by exactly the same pipeline as wasm since at least 2019. In fact, the way we compile it is literally to construct a pseudo-wasm module and run it through our wasm compiler (with a few flags to tweak the behavior to fit the asm.js semantics). In other words, if you're running asm.js in Firefox, you're literally just running wasm anyway, so how could it possibly be faster?

Furthermore, if you use wasm, you'll have fewer bounds checks (because of better memory allocation strategies[1]), access to SIMD, bulk memory operations, and a host of other niceties that have been added to wasm over the years. If your asm.js code is outperforming someone else's wasm code, that probably just means their wasm code is worse.

[1]: https://spidermonkey.dev/blog/2025/01/15/is-memory64-actuall...

theultdev 7 hours ago||
yeah turns out it was chrome that was slow, not firefox.

wasm hashing in chrome is half the speed of firefox for me.

https://theultdev.github.io/web-sha256-benchmark

lukan 11 hours ago|||
That is surprising. Do you know the reasons? Is it a special use case or was asm really faster? I find that hard to believe.
theultdev 11 hours ago||
It's a custom solution, but nothing special just incremental hashing for large files.

I took off the shelf wasm crypto libraries to compare it, but the leading one was 10x slower.

throawayonthe 10 hours ago||
can we see?
theultdev 10 hours ago||
yeah check back at the end of the day.

will try to rip it out of the project and put it in a standalone benchmark.

titzer 10 hours ago||
It'd be interesting to compare it to a SHA-256 algorithm that uses Wasm simd: https://github.com/ChrisWhealy/wasm_sha256
theultdev 10 hours ago||
Noted, will add that.

Last time I tried https://github.com/Daninet/hash-wasm

edit: I focus on browsers, that's wasm but not for browser envs.

----

https://theultdev.github.io/web-sha256-benchmark

https://github.com/TheUltDev/web-sha256-benchmark

seems it is chrome wasm that is slow.

asmjs is about the same speed in chrome and firefox (with asm optimizations still enabled) but wasm is slow as hell in chrome, asm still better.

side note: someone mentioned native crypto.subtle, but that doesn't have incremental hashing so can't use it for large files. however I do use it in practice for smaller files.

theultdev 7 hours ago|||
Made the requested benchmark:

https://theultdev.github.io/web-sha256-benchmark

https://github.com/TheUltDev/web-sha256-benchmark

It's Chrome wasm (windows) that is slow for me, 2x slower than asmjs.

FF with asmjs optimizations are 2x slower than wasm on FF.

Wasm in FF is 2x faster than wasm in Chrome for this hashing solution (for me).

dist-epoch 9 hours ago||
what's wrong with the built in one?

https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt...

wren6991 9 hours ago|||
Requires a secure origin. If you serve a local (but non-localhost) SPA over HTTP then you're blocked from using crypto.subtle.digest. At least, that is one reason I have seen a hand-rolled SHA-256 deployed.

Edit: oh, and it forces async.

theultdev 7 hours ago|||
no incremental hashing, so you can't hash files too large for ram.

I do use it for smaller files though, it's much faster.

danborn26 5 hours ago||
[dead]
css_apologist 11 hours ago|
o7