June 27th, 2024

Why Google Sheets ported its calculation worker from JavaScript to WasmGC

Google Sheets transitioned its calculation worker to WasmGC from JavaScript for improved performance. Collaboration between Sheets and Chrome teams led to optimizations, overcoming challenges for near-native speed on the web.

Read original articleLink Icon
Why Google Sheets ported its calculation worker from JavaScript to WasmGC

Google Sheets transitioned its calculation worker from JavaScript to WasmGC, a move announced in 2022. The Sheets and Chrome teams collaborated on standardization and tooling to optimize performance. Initially written in Java in 2006, the calculation engine shifted to JavaScript in 2013, resulting in slower performance compared to the Java version. WasmGC, an extension of WebAssembly, was chosen for its potential to bring garbage collected languages to the web at near-native speed. The migration faced challenges such as tooling and library replacements, but optimizations like replicating core JVM and V8 optimizations, utilizing browser APIs, and removing JavaScript-specific patterns improved performance. The Sheets team's efforts led to a prototype running on WasmGC by late 2021, with subsequent optimizations narrowing the performance gap with JavaScript. Google aims to further enhance WasmGC for shared memory multithreading and single-threaded performance, encouraging developers to consider it for high-performance web projects.

Related

20x Faster Background Removal in the Browser Using ONNX Runtime with WebGPU

20x Faster Background Removal in the Browser Using ONNX Runtime with WebGPU

Using ONNX Runtime with WebGPU and WebAssembly in browsers achieves 20x speedup for background removal, reducing server load, enhancing scalability, and improving data security. ONNX models run efficiently with WebGPU support, offering near real-time performance. Leveraging modern technology, IMG.LY aims to enhance design tools' accessibility and efficiency.

Wc2: Investigates optimizing 'wc', the Unix word count program

Wc2: Investigates optimizing 'wc', the Unix word count program

The GitHub project "wc2" presents an innovative algorithm for the `wc` program, focusing on asynchronous state-machine parsing in C and JavaScript. It enhances efficiency, scalability, and speed compared to traditional `wc` implementations.

What Happens When You Put a Database in the Browser?

What Happens When You Put a Database in the Browser?

WebAssembly (Wasm) enhances browser capabilities, enabling high-performance apps like DuckDB for ad-hoc queries and Python environments. DuckDB Wasm boosts performance in interfaces like lakeFS, Evidence, and Count. MotherDuck enables local querying, emphasizing efficient data processing.

Google no longer developing Material Web Components

Google no longer developing Material Web Components

Material Web is a library of web components based on Material 3 for creating attractive and accessible web apps. Components are in maintenance mode, seeking new maintainers. Visit the Material Web GitHub for details.

Google no longer developing Material Web Components

Google no longer developing Material Web Components

Google has ceased active development of Material Web Components (MWC) and shifted focus to its internal Wiz framework. MWC is now in maintenance mode, with engineers reassigned. Angular Material remains available.

Link Icon 30 comments
By @markdog12 - 4 months
Maybe I'm missing it, but it says it was originally twice as slow as JS, than it says they did optimizations, then no comparison on the final outcome?
By @dgb23 - 4 months
I didn't know WasmGC was a thing yet!

https://developer.chrome.com/blog/wasmgc/

Some things that are at first glance surprising is that GC'ed languages might ship a smaller binary, because they don't need to include the code that manages memory. (The example here was Java.)

When WasmGC is widely adopted, we might hopefully see some languages adopting it as a target instead of JS. I'm thinking of Clojure and Dart specifically but there are plenty of other languages that might benefit here.

This could also have an impact on "edge computing" (isolates etc.) down the line.

By @tjlav5 - 4 months
It’s perhaps telling that they had an initial prototype which was 2x slower, then talk about specific optimization strategies but never share the updated overall speed comparison.
By @londons_explore - 4 months
Anyone here actually bothered by the speed of the core calculation engine of Google sheets?

I'm bothered by the sluggishness of the UI, but I've never typed '=A1+A2' in a box and found it takes too long to get an answer.

Even if it did, I'd kinda like million row X million column sheets to somehow be server side and my machine simply views a local window, and calculations happen locally if feasible with locally available data, or server side otherwise.

By @mirkodrummer - 4 months
They also mention that “there are cases where browser APIs are backed by optimized native implementations that are difficult to compete with using Wasm … the team saw nearly a 100 times speedup of regular expression operations when switching from re2j to the RegExp browser API in Chrome” if so how they call RegExp from WasmGC or viceversa? 100 times speedup for native web apis is not something you can ignore, that’s the important lesson here, not everything compiled to wasm will result in a speed again
By @davexunit - 4 months
Nice to hear from teams building with Wasm GC. They bring up the "shared everything" proposal [0] for enabling heap objects to be shared across the threads. In addition to this, I'd like to be able to share the contents of a packed array, such as a (ref (array i8)), with the host. Right now, only Wasm memory objects have ArrayBuffer access in JS. Providing the same shared access to packed GC arrays would unlock things like WebGL, WebGPU, and Web Audio for Wasm GC applications. I made a "hello triangle" WebGL program with Wasm GC awhile back, but there's no way that I know of to get acceptable throughput when working with GPU buffers because they have to be copied byte-by-byte at the Wasm/JS boundary.

[0] https://github.com/WebAssembly/shared-everything-threads/blo...

By @ZuLuuuuuu - 4 months
As somebody who is not familiar with how garbage collection is implemented at the low level, can somebody explain why WasmGC is needed on top of Wasm?

For example, isn't CPython a C program and hence can just be compiled to Wasm, including its garbage collection part? Does garbage collection usually depend on OS specific calls, which are not part of C standard?

By @hankman86 - 4 months
It is not entirely clear from the article, but apparently, they still use Java for their calculation engine. And then transpile it into JavaScript. Which makes me wonder whether instead of porting this code base to WasmGC, a partial rewrite would have helped the project’s maintain ability in the long run. Rust seems like a potentially good candidate due to its existing WebAssembly backend.

WasmGC is useful for many other projects of course. But I wonder how painful it is to maintain a Java code base, which is not a great choice for client-side web apps to begin with. I remember using GWT back in the days - and that never felt like a good fit. GWT supported a whitelisted subset of the Java standard library. But the emitted Javascript code was nigh on impossible read. I don’t remember if Chrome’s developer tools already had source map support back in those days. But I doubt it. Other core Java concepts like class loaders are equally unsuited for JavaScript. Not to mention that primitive data types are different in Java and JavaScript. The same is true for collections, where many popular Java classes do not have direct counterparts in JavaScript.

By @Vt71fcAqt7 - 4 months
They forgot to mention the final speedup:

>The initial version of Sheets Wasm showed calculation performance roughly two times slower than JavaScript.

>[...]

>Implementing speculative inlining and devirtualization—two very common optimizations—sped up calculation time by roughly 40% in Chrome.

So the only numbers we get are 2x slowdown and the 1.4x speedup, which makes it sound like it's still slower. I'm sure thats probably not the case but it is a strange way to write an article advertising wasm.

Also, I'm a bit confused about which language this was actually written in before the wasm switch. Was it always written in Java and transpiled to JS? It doesn't seem that way from the article:

>Removing JavaScript-specific coding patterns.

>they had a core data structure in Sheets which was blurring the lines between arrays and maps. This is efficient in JavaScript

which doesn't make sense if they were writing it in Java and transpiling to JS.

Was it transpiled to JS only once in 2013 and then developed in JS from there? In which case why go back to Java?

By @boutell - 4 months
With infinite effort, a company with infinite resources made something that is already objectively fast enough twice as fast!

They are right though that wasmgc might have a bigger impact than wasm alone. Lots of attention is deservedly paid to Rust but people use garbage collected languages more.

By @bahmboo - 4 months
This is the kind of cool cutting edge web development that google excels at. Hopefully there are some down stream effects that help more tools move to the web. Good work!
By @bhl - 4 months
It seems this is not a full rewrite of the calculation engine, so it’s hard to compare the performance of JavaScript against WASM.

Has anyone rewritten a performant calculation in that way from JavaScript to WASM? I’m curious to what the performant gap is, and whether browser optimizations are closing or widening that gap.

By @pjmlp - 4 months
I love how we are slowly back to Applets and related plugins.

WebGL | WebGPU + WasmGC => Flash!

By @sirjaz - 4 months
Maybe they can finally make Google Sheets, etc... off-line stand alone app.
By @bbor - 4 months
Slightly off topic, but since the GenAI push google has started investing heavily into its devtools again, namely Sheets and Colab. Either that or these teams are just that good! If you haven't checked out the recent "Tables" update to Sheets, I highly recommend it -- probably the most meaningful improvement in years.
By @murkle - 4 months
When will Safari have WasmGC?
By @tsujp - 4 months
I'll need to look into this but if anyone knows: is this available (easily) as a standalone package somewhere; think using the engine from a CLI without needing or contacting Google Sheets at all.
By @cxr - 4 months
> they had a core data structure in Sheets which was blurring the lines between arrays and maps. This is efficient in JavaScript, which automatically models sparse arrays as maps, but slow on other platforms. So they had to rewrite the code in a more platform-agnostic way. This is another thing the team like about WebAssembly: it makes it easier for multiplatform applications to get good performance on the web. You don't have to bend your whole application to the idiosyncrasies of JavaScript.

Uh, that's a terrible example. It's not an example of anyone forced to "bend their whole application to the idiosyncrasies of JS" at all. It's almost the opposite

Someone wrote the code they wanted to write, whether in good taste or not, and the JS runtimes that the product was tested on handled it efficiently (to their credit!); i.e., the authors of those JS runtimes had to bend their implementations to accommodate the idiosyncrasies of people who were/are writing code like that.

By @zengid - 4 months
This is really cool, I wonder what .NET to wasmGC would be like.
By @zengid - 4 months
WasmGC: Revenge of the JVM
By @AshleysBrain - 4 months
This is a bit of a tangent but it always annoys me when content has no published date next to it. There's a tiny "last updated" date at the bottom. But how do we know if this is a new article or one from a few years back? With technology moving so fast it can significantly change the context in which you read an article.
By @royjacobs - 4 months
It's great to see Java Web Start finally being used in anger 24 years after its initial release.
By @whoomp12342 - 4 months
Why is javascript slower than java?

uhhhh I don't think there is actually a real answer in that paragraph that compares PERFORMANCE of JS to JAVA.

that explanation is completely unhinged?

By @bongwater_OS - 4 months
is this why all my gsheets scripts started failing out of nowhere today
By @macspoofing - 4 months
Google finally got NaCL/Pepper into the browser.
By @davidmurdoch - 4 months
I still long for a world where we got ASM.js and SIMD directly in JavaScript.
By @devit - 4 months
How about writing it properly in an efficient language that doesn't use a GC? (i.e. Rust or something equivalent)