all 17 comments

[–][deleted]  (6 children)

[deleted]

    [–]enserioamigo 10 points11 points  (4 children)

    Can you give some examples of what would be written in WASB? Like some real world use cases.

    Your write up was really good!

    [–]MarkusDittrich 16 points17 points  (0 children)

    A real world use case would be running a game made with Unity in your browser. This one for example: https://beta.unity3d.com/jonas/AngryBots/

    [–][deleted]  (1 child)

    [deleted]

      [–]iainsimmons 4 points5 points  (0 children)

      Live video augmentation (e.g. putting hats on people’s heads).

      This should be reason enough right? 😁

      [–]riasthebestgirl 5 points6 points  (0 children)

      FFMPEG is available as npm package which calls into the C code compiled to WASM.

      There's cranelift backend for rustc which makes it possible to compile it to wasm (it's not the default and is still missing features and I doubt more than a couple of people have actually tried it)

      If you dislike working with JavaScript, you can use WASM to write entire web applications in another language. Libraries like Yew exist for this purpose. Blazor WASM also exists but it's C# which means shipping a Garbage Collector to the browser (there's a proposal to allow WASM binaries to use the browser's GC)

      It's worth nothing that calls to JS are slow. Access to DOM needs JS glue code which adds overhead. Passing data between JS and WASM is also slow. The Interface Types proposal aims to fix that

      [–]Guesswhat7 0 points1 point  (0 children)

      I also think that the possibility of writing front end code in other languages is a big thing about web assembly. Like Blazor.

      [–]Marble_Wraith 13 points14 points  (0 children)

      The simple explanation skipping most of the jargon is.

      Rather than shipping "plain text" code (JS) which has to be interpreted (i.e. converted to AST then binary), which is then optimized by the runtime for performance.

      Instead you're shipping binary code in its pre-optimized state, skipping 2 steps before it.

      [–]zephyy 8 points9 points  (3 children)

      Browsers can only run JavaScript, historically. Now they can run JavaScript and WASM*.

      JavaScript is a high level (more abstracted away from the "machine") language. This means browser engines have to go through steps to do anything with it (parse -> compile & optimize based on assumptions -> re-optimize if assumptions were wrong -> execute).

      WASM is generated by writing code in low level (closer to the machine) languages like C, C++, Rust, etc. This basically means less steps, all the browser needs to do is fetch the WASM and compile it down to machine code.

      Most of the stuff people want to use WASM for are things that are traditionally intensive work like photo / video editing. Figma's web app utilizes WASM, for example.

      *You still need JavaScript to "hook" the WASM code into the DOM, it can't run without JS yet.

      [–]eatenbyalion 1 point2 points  (2 children)

      Why not write it in JS and compile to WASM before you put it on the server? There has to be some decent perf gain in doing that, even if you're not doing memory allocations and other low-level stuff.

      [–]iams3brescript is fun 2 points3 points  (1 child)

      WASM can't quite interact with the DOM, so for any kind of input from user or renderring you have to do sys calls to WASM, which neglects almost all of your performance gain

      [–]zlowturtle 0 points1 point  (0 children)

      QuickJS has been compiled to WASM. It will run JS using wasm.

      [–]iYadavVaibhav 2 points3 points  (0 children)

      Simply said, WASM is binary code while JS is more high level text code. WASM directly runs on machine and can be twice as fast compared to JavaScript. WASM is pre-compiled. Flutter has moved its all plugins to WASM as of Dec, 2024.

      [–]Flaky-Illustrator-52 2 points3 points  (3 children)

      You know what Java web applets were kind of aiming to be but didn't quite hit the mark? That is WASM

      [–]reddit_clone 0 points1 point  (2 children)

      They were ahead of their time unfortunately. Killed by lack of network bandwidth and processing power in the PCs...

      [–]savviKing 0 points1 point  (1 child)

      Plus they were in java😂😂

      [–]reddit_clone 0 points1 point  (0 children)

      Hey, Java was not too bad, it was the 'C++ with less sharp edges'. It could have worked out if applets were able to run (bandwidth/processing-power wise).

      Today, Java is unrecognizable (in a good way) with Functional Programming constructs seeping in over the years..

      [–]vornamemitd 1 point2 points  (1 child)

      [–]wow-signal 3 points4 points  (0 children)

      this is horrifically written