Comment by thegeomaster

Comment by thegeomaster 11 hours ago

6 replies

WASM nowadays has become quite the monstrosity compared to NaCl/PNaCl. Just look at this WASM GC spaghetti, trying to compile a GC'd language but hooking it up V8/JavaScriptCore's GC, while upholding a strict security model... That sounds like it won't cause any problems whatsoever!

Sometimes I wonder if the industry would have been better off with NaCl as a standard. Old, mature tooling would by and large still be applicable (it's still your ordinary x86/ARM machine code) instead of the nascent and buggy ecosystem we have now. I don't know why, but the JS folks just keep reinventing everything all the time.

duskwuff 9 hours ago

> Old, mature tooling would by and large still be applicable (it's still your ordinary x86/ARM machine code)

It wasn't, though. Since NaCl ran code in the same process as the renderer, it depended upon a verifier for security, and required the generated code to follow some unusual constraints to support that verification. For example, on x86, all branch targets were required to be 32-byte aligned, and all indirect branches were required to use a specific instruction sequence to enforce that alignment. Generating code to meet these constraints required a modified compiler, and reduced code density and speed.

In any case, NaCl would have run into the exact same GC issues if it had been used more extensively. The only reason it didn't was that most of the applications it saw were games which barely interacted with the JS/DOM "world".

  • thegeomaster 8 hours ago

    I simplified in my comment. It was a much better story for tooling, since you could reuse large parts of existing backends/codegen, optimization passes, and debugging. The mental model of execution would remain too, rather than being a weird machine code for a weird codesize-optimized stack machine.

    I would wager the performance implications of NaCl code, even for ARM which required many more workarounds than x86 (whose NaCl impl has a "one weird trick" aura), were much better than for modern WASM.

    It's hard to say if it would've run into the same issues. For one, it would've been easier to port native GCs: they don't run afoul of W^X rules, they just read memory if that, which you can do performantly in NaCl on x86 due to the segments trick. I also suspect the culture could've more easily evolved towards shared objects where you would be able to download/parse/verify a stdlib once, and then keep using it.

    I agree it was because the applications were games, but for another second-order reason: they were by and large C/C++ codebases where memory was refcounted manually. Java was probably the second choice, but those were the days when Java applets were still auto-loading, so there was likely no need for anybody to try.

    • duskwuff 6 hours ago

      > It's hard to say if it would've run into the same issues. For one, it would've been easier to port native GCs...

      WASM GC isn't just about memory management for the WASM world; it's about managing references (including cyclical refs!) which cross the boundary into the non-WASM world. Being able to write a GC within the WASM (or NaCl) world doesn't get you that functionality.

flohofwoe an hour ago

> WASM nowadays has become quite the monstrosity compared to NaCl/PNaCl

It's really the other way around, NaCl/PNaCl was quite the monstrosity that didn't fit into the browser runtime environment at all and required completely separate APIs to access 'platform features' - while access to existing web APIs had to go through an incredibly slow and cumbersome messaging layer - e.g. the people complaining today that WASM doesn't allow direct DOM access would have a complete mental breakdown with NaCl/PNaCl ;)

In a way, WASM is also an evolution of PNaCl (which was also a CPU-agnostic bytecode, but one that couldn't be standardized because it was an adhoc subset of LLVM IR).

zdragnar 10 hours ago

I'm reminded of writing JavaScript way back in the old Internet Explorer days (6 and to a lesser extent 7), when you had to manually null out any references to DOM elements if you were done with them, or else the JS and the DOM nodes wouldn't get garbage collected because IE had two different garbage collectors and cycles between them didn't get collected immediately.

Vampiero 8 hours ago

> I don't know why, but the JS folks just keep reinventing everything all the time.

It's because they only know the web. They have never seen seen what real programmers actually do. They only live in their stupid web bubble thinking it's all there is.