How Notion Boosted Browser Speed with WASM SQLite

0

We consume information in the digital world every day, but we’ve all experienced frustration with slow page load times, haven’t we? Notion has introduced groundbreaking technology to solve this issue. Today, we’ll explore how Notion improved browser speed by 20% using WASM SQLite.

notion blog

Notion’s Innovation: Adopting WASM SQLite

Three years ago, Notion significantly improved speed by caching data using the SQLite database in its Mac and Windows apps. This innovative approach has now been applied to browsers. With the adoption of WASM (SQLite), Notion has reduced page navigation time by 20% in all modern browsers. This improvement was especially noticeable in environments with slow API response times.

Performance Improvement by Region

  • Australian users: 28% faster page navigation
  • Chinese users: 31% speed improvement
  • Indian users: 33% reduced load time

The Fusion of WebAssembly and SQLite

Notion utilized SQLite3 implemented in WebAssembly (WASM) to enhance performance. Through this technology, Notion maintained data across sessions by leveraging the browser’s OPFS (Origin Private File System). OPFS is only accessible within Web Workers, which operate on separate threads.

Collaboration of Web Worker and SharedWorker

Notion dedicated a Web Worker for each tab and managed active tabs through a SharedWorker. This architecture allowed each tab to execute SQLite queries without concurrency issues. Additionally, the Comlink library was used to facilitate message passing between the main thread and Workers.

Key Challenges and Overcoming Them

Cross-Origin Isolation

To use OPFS, the site had to be in a “cross-origin isolated” state, which required setting up numerous security headers—a considerable task. Notion temporarily bypassed this challenge using Origin Trials to gather performance data.

Data Corruption Issues

A small number of users experienced data corruption due to improper handling of concurrency across multiple tabs. Notion successfully reduced the corruption rate by adding Web Locks and ensuring only the focused tab could write to SQLite.

Issues on Slower Devices

Some older Android phones experienced decreased performance due to disk caching. To address this, Notion implemented logic to compete between the API and SQLite cache, achieving performance improvements across all devices.

Conclusion: The Harmony of Technology and Innovation

Notion’s performance enhancements are a result of technical challenges and innovation. The 20% improvement in page navigation times through SQLite caching in browsers is a significant achievement. This success is attributed to the official WASM implementation team of WebAssembly and SQLite, as well as the experimental approach provided by Roy Hashimoto.

Reference: Notion, “How we sped up Notion in the browser with WASM SQLite”

Leave a Reply