‹ BackHN Continuity

Thread

The JavaScript Midlife Crisis

56 points · 75 comments · maroun-baydoun

  1. cisc · · focus · HN ↗
    > I start wondering what we're supposed to do with all those precious milliseconds it just handed us back

    Speed matters. WebAssembly is taking jobs from JavaScript precisely because it's faster.

    The calculation engine for Google Sheets became twice as fast with the switch to WebAssembly: <a href="https:&#x2F;&#x2F;web.dev&#x2F;case-studies&#x2F;google-sheets-wasmgc" rel="nofollow">https:&#x2F;&#x2F;web.dev&#x2F;case-studies&#x2F;google-sheets-wasmgc

    The Amazon Prime Video app became twice as fast with less variability in performance when they switched to WebAssembly: <a href="https:&#x2F;&#x2F;www.amazon.science&#x2F;blog&#x2F;how-prime-video-updates-its-app-for-more-than-8-000-device-types" rel="nofollow">https:&#x2F;&#x2F;www.amazon.science&#x2F;blog&#x2F;how-prime-video-updates-its-...

    Compiling to WebAssembly enables every language to run in the browser. Google used Java and Amazon used Rust.

    1. suplexer · · focus · HN ↗
      1) Google Sheets use case

      Long story short they are comparing the performance of server-side Java to client-side JS (Java transpiled through GWT&#x2F;J2CL). So something like: Java -&gt; Hotspot -&gt; native vs Java -&gt; GWT&#x2F;J2CL -&gt; JS -&gt; V8 (in Chrome) -&gt; native

      Apples to oranges.

      They then used J2CL (I presume, not clear from the article) to port Java to Wasm and eventually got around 66% of the server-side Java performance. The Wasm performance story also was nowhere near straightforward - hence the immense efforts spent on optimizing WasmGC and validating the transpiler output.

      The root of the problem is likely the GWT&#x2F;J2CL transpiler output. There shouldn&#x27;t be that much of a peformance drop off between to high-level languages if you&#x27;re transpiling with speed in mind. I bet there are probably lots of expense runtime checks in the generated output, among others things.

      2) Amazon Prime Video use case

      Blog seems mostly fine on the surface. But my complaints are always the claims about the limits of performance one could get from a JS-based system - especially in environments where you can call out into native audio&#x2F;visual libraries.

      &quot;In those experiments, code written in Rust and compiled to Wasm was 10 to 25 times as fast as JavaScript.&quot;

      What does the JS versus Rust code look like? Are they using the similar libraries&#x2F;graphics apis&#x2F;techniques? Did they exhaust every possible low-level tool in JS (Worker Threads, SharedMemory, etc). I feel there are a also rainbow of optimization opportunities available if one controls V8 and the underlying C++ stack.

      Not that their eventual Wasm architecture is bad per se, it&#x27;s just layering Rust+JS -&gt; Wasm&#x2F;C++ is much more complex than simply JS -&gt; C++ back and forth.

      As a side note, it very annoying that SIMD was taken out of development for JS. Big TC39 wants wants JS to fail.

      <a href="https:&#x2F;&#x2F;github.com&#x2F;tc39&#x2F;ecmascript_simd" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tc39&#x2F;ecmascript_simd

      1. cisc · · focus · HN ↗
        In both cases the WebAssembly result is twice as fast as the JavaScript version.

        How do you account for that?

        1. suplexer · · focus · HN ↗
          In Google sheets case, because they are being processed through two separate transformation pipelines, then they compare the result from different runtime environments (i.e. server vs client). The automated translation via J2CL is surely producing very suboptimal code in JS versus Wasm. The end result doesn&#x27;t matter if it&#x27;s incomparable.

          In Amazon&#x27;s case, are they using specialized vector instructions (i.e. SIMD) in the Rust version, different graphics apis, specialized algorithms? They just said it&#x27;s 10 to 25 times faster with no code. Ok...sure.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.