Hacker News new | ask | show | jobs
by LunaSea 35 days ago
String manipulation for HTML is a great way to introduce security vulnerabilities.

WASM is a non-starter for most web applications due to initial binary download.

Advising to use some experimental feature in one browser does not seem like a great idea.

JavaScript frameworks are not perfect but they exist for good reasons. People that brush them away usually lack the experience and understanding on the topic.

1 comments

I don't disagree or really have a dog in the fight for three out of your four points, but it's unfortunate that WASM gets such a bad rap. The blobs are large because popular compilers force the semantics of popular languages into the Turing tar pit. WASM binaries are pretty compact by design:

    const binary = Uint8Array.fromBase64(
        "AGFzbQEAAAABBgFgAX8BfwMCAQAHBgECeDIAAAoJAQcAIABBAmwL"
    );
    const module = new WebAssembly.Module(binary);
    const instance = new WebAssembly.Instance(module, {});
    console.log(instance.exports.x2(3));
This is a trivial and useless example at 39 bytes, but a real example could be more compact than comparable minified JavaScript.
I want this to be true too but you’re essentially proving the point by demonstrating you have to write the wasm by hand if you want it to be compact.
I don't think that wasm is inherently uncompressible. I think it's more that tools like emscripten include the entire C++ standard library because most existing libraries expect them to just be available for free. But hopefully that would change as more web focused libraries are created.
A small set of changes to AssemblyScript could do this, but most people would still grab for Emscripten with a shadow stack and asyncify hacks.
no, you can write c/c++ or rust
actually minified js is super compact. representing things as string immediately gives you the advantage of basic variable length encoding, whereas most binary formats will give you 32 to 64 bit integers with weird paddings for most structure fields. Afaik WASM also uses SSA forms which are super big compared to more compact representations such as RPN
Everything you said about WASM is false. It uses a variable length encoding for integers (LEB128). It presents as a stack machine (RPN) not SSA. It doesn't expose or impose padding in structs.

It seems like you're extrapolating from things you know to something you don't know at all, and you're spreading misinformation. WASM was designed to be compact.

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.

No worries, and I apologize if I was too blunt.

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.

> Maybe I misunderstand, but I'm not sure I see the point about hard working engineers or memory mapping

I was just saying, in my experience, binary formats tend to be easier to parse than text, relying on machine native constructs such as binary integers, sometimes even matching up their stored formats to C struct layouts (this is the case with, Linux's inode format for example).

Whereas complex textual formats such as JSON or Javascript usually have a tokenization and parsing pass. But they are mostly human readable in exchange, which is a ton more engineering effort to build and CPU time to run.

I was just trying trying to say, that once you really get into sophisticated binary formats, you have to take on similar levels of complexity to parsing something like a programming language, meaning that the parser is not simple, or fast, but the file is not human readable either. Which is kinda the worst of both worlds, and doesn't really drastically reduce file size.

TLDR: Text-based formats are fine, expecially for complex data, and are surprisingly competitive with hand-tuned binary formats.