Connect with us

Tech

Why Google Spreadsheets ported its calculation workers from JavaScript to WasmGC | web.dev

Why Google Spreadsheets ported its calculation workers from JavaScript to WasmGC | web.dev

 


Google Sheets is one of the first Google products to use WasmGC on Chrome. The move was announced in 2022, with the Sheets and Chrome teams partnering on standardization, engineering, tooling, and providing real-time feedback on optimizations. This partnership set a precedent for how Google's engineering teams can effectively collaborate with Chrome to enable more Google apps to run on WasmGC.

Challenge: JavaScript

The Google Spreadsheets calculation engine was originally written in Java and released in 2006. In the early days of the product, all calculations were done on the server. However, since 2013, the engine has been running in the browser using JavaScript. This was initially achieved by the Google Web Toolkit (GWT), and later by the Java to Closure JavaScript transpiler (J2CL). The JavaScript calculation engine runs in a Web Worker and communicates with the main thread using a MessageChannel.

Migrating users from the server to the JavaScript version of the calculation engine (and later from GWT to J2CL) was a big undertaking that required careful validation. To ensure that the JavaScript calculation engine produced exactly the same results as the Java version, the Sheets team developed an internal validation mechanism that could handle large volumes of sheets and validate that results were identical across multiple versions of the calculation engine. The Sheets team regularly uses this tool to validate changes to Sheets. However, in addition to comparing calculation results, the team also compared the performance of JavaScript on the client and Java on the server. The results showed that the JavaScript version of the calculation engine was more than three times slower than the Java version.

Why is JavaScript slower than Java?

JavaScript is fast for a loosely typed dynamic language. Heavy investment in just-in-time (JIT) compilers (Maglev, Sparkplug, Turbofan, etc.) over the past 15 years has improved JavaScript performance. However, JavaScript's loosely typed and dynamic behavior makes it difficult for JIT compilers to generate optimal code. This means that JavaScript lags behind languages ​​like Java and C++ in terms of raw throughput. TypeScript adds type safety to JavaScript, but that type information is there to make development easier, not to provide the kind of guarantees that compilers need to generate optimal code. In cases like Google Spreadsheets, where large spreadsheets take tens of seconds to calculate, JavaScript is fast, but not fast enough.

Solution: WasmGC

WasmGC is an extension to the existing WebAssembly specification that adds primitives necessary for compiling garbage collected languages ​​(such as Java). For example, WasmGC adds instructions for defining types and allocating garbage collected data structures. WasmGC intends to do for garbage collected languages ​​what Wasm did for C++ (such as Photoshop and Google Earth): bring them to the web at near-native speeds. Google believes that WasmGC has the potential to be even more influential than Wasm due to the popularity of garbage collected languages.

Google Workspace partners with Chrome

The WasmGC MVP draft specification was published in 2019. In late 2020, Google Workspace and Chrome partnered to evaluate WasmGC using Spreadsheets' calculation engine. Workspace's multi-platform team has extensive expertise in building and optimizing compilers and transpilers. Spreadsheets, which is part of Workspace, was identified as an ideal candidate to evaluate WasmGC because it is performance-sensitive and has robust performance and correctness validation mechanisms. Chrome has the V8 team building and optimizing the WasmGC runtime, and Binaryen contributors building ahead-of-time (AOT) optimizations. Between Chrome and Workspace, we have all the expertise we need to build and optimize the WasmGC toolchain, with Google Spreadsheets as an ideal testbed.

First Prototype

By mid-2021, the team had a working Java-to-WasmGC compiler. By the end of the same year, they were running a prototype version of Google Spreadsheets as a WasmGC and performing calculations. Along the way, they faced many challenges. Tools for profiling and taking heap dumps did not exist, so they had to be built. The existing implementation relied on many JavaScript libraries, so replacements had to be found or created for WasmGC. Validating the correctness of the Wasm calculation engine was a time-consuming task, given the nature of the specification, compiler, and new libraries. However, Spreadsheet's validation mechanism was very helpful here as well. The team finally got everything working, and in early 2022 they started getting performance data.

Additional optimizations

In the initial version of Sheets Wasm, we found that the calculation performance was about twice as slow as JavaScript. However, given the new specification, the new compiler, and some new libraries, this is not a bad result. From this point on, the Sheets team started optimizing. Among the optimizations they found, there were several categories:

It replicates core optimizations already present in the Java Virtual Machine (JVM) and V8. It uses highly optimized browser APIs. It removes JavaScript-specific coding patterns.

First, the Sheets team had to reproduce optimizations that already exist in other toolchains. The best example is the virtual method dispatch optimization, which has been optimized for a long time in the JVM and V8, but had nothing in WasmGC. By implementing two very common optimizations, speculative inlining and devirtualization, the team was able to speed up computation times in Chrome by about 40%.

The second is when the browser API is backed by an optimized native implementation, which is hard for Wasm to compete with. Strings and regular expressions are a good example. Specifically, for regular expressions, the team saw almost 100x speedups in regular expression operations when they switched from re2j (which compiled to WasmGC) to Chrome's RegExp browser API, which allows each regular expression to be compiled to its own machine code.

Finally, it became clear that years of optimization had caused the codebase to become overly adapted to JavaScript. For example, Sheets' core data structures blurred the boundary between arrays and maps. This was efficient in JavaScript, which automatically models sparse arrays as maps, but slow on other platforms. So the code had to be rewritten in a platform-agnostic way. This is another reason the team loves WebAssembly: it makes it easier for multiplatform applications to achieve great performance on the web, without having to tune the entire application for the idiosyncrasies of JavaScript.

Conclusion

WasmGC is a powerful technology that has the potential to evolve the way developers build web applications. We expect to see WasmGC evolve over the next few years to support shared memory multithreading and further improve single-threaded performance. We encourage all web developers to consider using WasmGC for their next high-performance project. Join us and make the web a faster, smoother place.

Acknowledgements

We would like to thank the following people who helped with the implementation of WasmGC and this case study: Diwas Adhikary, Matthew Albright, Ksenia Bukina, Julien Dramaix, Asim Fazal, Michael Frederick, Goktug Gokdogan, Janice Gu, Adam Klein, Manos Koukoutos, Jakob Kummerow, Matthias Liedtke, Thomas Lively, Roberto Lublinerman, Vishrut Mehta, Thomas Nattestad, Josh Pearlstein, Joaquim Perotti, Chris Ruenes, Steven Saviano, Derek Schuff, Tim Sears, Michael Thomas, Yuan Tian, ​​Philipp Weis, Mason Wu, Alon Zakai, and Emanuel Ziegler.

Sources

1/ https://Google.com/

2/ https://web.dev/case-studies/google-sheets-wasmgc

The mention sources can contact us to remove/changing this article

What Are The Main Benefits Of Comparing Car Insurance Quotes Online

LOS ANGELES, CA / ACCESSWIRE / June 24, 2020, / Compare-autoinsurance.Org has launched a new blog post that presents the main benefits of comparing multiple car insurance quotes. For more info and free online quotes, please visit https://compare-autoinsurance.Org/the-advantages-of-comparing-prices-with-car-insurance-quotes-online/ The modern society has numerous technological advantages. One important advantage is the speed at which information is sent and received. With the help of the internet, the shopping habits of many persons have drastically changed. The car insurance industry hasn't remained untouched by these changes. On the internet, drivers can compare insurance prices and find out which sellers have the best offers. View photos The advantages of comparing online car insurance quotes are the following: Online quotes can be obtained from anywhere and at any time. Unlike physical insurance agencies, websites don't have a specific schedule and they are available at any time. Drivers that have busy working schedules, can compare quotes from anywhere and at any time, even at midnight. Multiple choices. Almost all insurance providers, no matter if they are well-known brands or just local insurers, have an online presence. Online quotes will allow policyholders the chance to discover multiple insurance companies and check their prices. Drivers are no longer required to get quotes from just a few known insurance companies. Also, local and regional insurers can provide lower insurance rates for the same services. Accurate insurance estimates. Online quotes can only be accurate if the customers provide accurate and real info about their car models and driving history. Lying about past driving incidents can make the price estimates to be lower, but when dealing with an insurance company lying to them is useless. Usually, insurance companies will do research about a potential customer before granting him coverage. Online quotes can be sorted easily. Although drivers are recommended to not choose a policy just based on its price, drivers can easily sort quotes by insurance price. Using brokerage websites will allow drivers to get quotes from multiple insurers, thus making the comparison faster and easier. For additional info, money-saving tips, and free car insurance quotes, visit https://compare-autoinsurance.Org/ Compare-autoinsurance.Org is an online provider of life, home, health, and auto insurance quotes. This website is unique because it does not simply stick to one kind of insurance provider, but brings the clients the best deals from many different online insurance carriers. In this way, clients have access to offers from multiple carriers all in one place: this website. On this site, customers have access to quotes for insurance plans from various agencies, such as local or nationwide agencies, brand names insurance companies, etc. "Online quotes can easily help drivers obtain better car insurance deals. All they have to do is to complete an online form with accurate and real info, then compare prices", said Russell Rabichev, Marketing Director of Internet Marketing Company. CONTACT: Company Name: Internet Marketing CompanyPerson for contact Name: Gurgu CPhone Number: (818) 359-3898Email: [email protected]: https://compare-autoinsurance.Org/ SOURCE: Compare-autoinsurance.Org View source version on accesswire.Com:https://www.Accesswire.Com/595055/What-Are-The-Main-Benefits-Of-Comparing-Car-Insurance-Quotes-Online View photos

ExBUlletin

to request, modification Contact us at Here or [email protected]