|
|
|
|
|
by torginus
34 days ago
|
|
Sorry I am not an expert on WASM, I just listed thing that are generally true of binary formats, and my main point was that text formats like minified js are pretty good when it comes to size - im sure a tiny js module would beat your wasm example. The thing is to get these optimizations, like variable length encoding and tightly packed structs, engineers had to work hard, while a dumb text format gives it for free. Additionally, they gave up the biggest advantage of binary formats - that they can be mmap-ed directly and read from code. |
|
We'd have to get pretty specific to have a real bake-off on size, and that's probably more effort than either of us wants to spend for a HN thread that's basically dead. I could invent scenarios where either of JS or WASM has the advantage.
Code-golfing that particular example though, the JS could be "const x2=a=>2*a;" (15 bytes). If you ignore the one-time (insignificant) costs for the WASM headers and sections, the comparable byte code for that export is about the same number of bytes. If JS wins, it doesn't win by a lot.
Maybe I misunderstand, but I'm not sure I see the point about hard working engineers or memory mapping. I'm sure the JavaScript JIT engineers had to work really hard to get good performance. Among many other things, JS Objects using "shapes" or "hidden classes" was a pretty clever way to compensate for not having structs at all. For both JS and WASM, end developers don't need to worry about it, and you can't mmap JS to execute the code either.