Figma Rendering: How WebAssembly and WebGL Work Together
In this article
Figma renders its interface by using WebAssembly (Wasm) to execute a high-performance C++ engine that calculates the geometry of the canvas, which then sends drawing commands to the GPU via WebGL. Instead of relying on the browser's standard Document Object Model (DOM) to render shapes, Figma treats the browser window as a blank canvas, drawing every pixel manually to ensure consistent performance across different operating systems.
The Limitations of the Browser DOM
To understand why Figma uses WebAssembly and WebGL, one must first understand the limitations of standard web development. Most websites are built using HTML, CSS, and JavaScript, where the browser manages a tree of elements called the DOM. When a user moves a rectangle in a standard web app, the browser must recalculate the layout, repaint the affected areas, and manage the styling of that specific element.
For a professional design tool, the DOM is insufficient for several reasons:
- Scaling: A complex design file can contain thousands of vectors, groups, and layers. Managing these as individual DOM elements would cause massive memory overhead and sluggish performance.
- Precision: Design tools require sub-pixel precision and complex mathematical transformations that are computationally expensive in JavaScript.
- Consistency: Different browser engines (WebKit, Blink, Gecko) render CSS slightly differently. For a tool where a single pixel matters, this inconsistency is unacceptable.
The Role of WebAssembly (Wasm)
Figma's core logic is written in C++. Traditionally, C++ cannot run directly in a browser. WebAssembly changed this by providing a binary instruction format that allows compiled code to run at near-native speed. Figma compiles its C++ engine into WebAssembly, which handles the "heavy lifting" of the application.
The WebAssembly layer is responsible for the application's state and geometry calculations, including:
- Vector Math: Calculating the Bézier curves and paths of vector shapes.
- Layout Engine: Determining the position and size of elements, including Auto Layout calculations.
- Constraint Logic: Handling how elements resize and move relative to their parent frames.
- Memory Management: Using a linear memory model to store the design document more efficiently than JavaScript's garbage-collected heap.
Rendering via WebGL
While WebAssembly handles the math, it cannot "draw" pixels on the screen directly. It needs an interface to communicate with the graphics hardware. This is where WebGL (Web Graphics Library) comes in. WebGL is a JavaScript API based on OpenGL ES, allowing the browser to utilize the device's GPU (Graphics Processing Unit).
The process follows a specific pipeline: the C++ engine in WebAssembly determines exactly what needs to be drawn, and then it sends a series of commands to the GPU via WebGL. Instead of telling the browser to "create a div," Figma tells the GPU to "draw these specific triangles with this specific color." Because GPUs are designed for parallel processing of thousands of vertices, this allows Figma to maintain 60 frames per second (FPS) even when zooming in and out of massive canvases.
The Hybrid Architecture in Action
Figma does not use WebAssembly and WebGL for everything. It employs a hybrid approach to balance performance with accessibility. The application is essentially split into two distinct layers:
- The Canvas (WebGL/Wasm): The actual design area where you draw shapes and move layers is rendered entirely via WebGL. This ensures that the zoom and pan experience is fluid and high-performance.
- The UI (HTML/CSS/React): The toolbars, layers panel, and properties panel are built using standard web technologies like React. These elements do not require high-frequency updates or complex geometry, so the DOM is the most efficient choice for building these interactive menus.
This separation allows Figma to keep the complex design engine isolated from the user interface, meaning a crash in the UI layer is less likely to corrupt the rendering of the actual design document.
Common Misconceptions About Figma's Tech Stack
A common misconception is that Figma is a "website" in the traditional sense. In reality, Figma is more akin to a desktop application that happens to be delivered through a browser. While it uses JavaScript for the outer shell and networking, the core engine is a compiled binary. This is why Figma feels significantly faster than other browser-based editors that rely solely on JavaScript for their rendering logic.
Another point of confusion is whether the "Desktop App" is different from the browser version. The Figma desktop app is essentially a wrapper (using Electron) around the same WebAssembly and WebGL engine. The primary advantage of the desktop app is not rendering speed—since both use the same engine—but rather better integration with local fonts and system-level shortcuts.
Frequently Asked Questions
Why doesn't Figma just use Canvas 2D?
The HTML5 Canvas 2D API is easier to use than WebGL, but it is primarily CPU-bound. For the scale of files Figma handles, the CPU would become a bottleneck. WebGL allows Figma to offload the rendering work to the GPU, which is far more efficient at handling the thousands of triangles required to render vector graphics.
Does WebAssembly make Figma slower to load?
Initially, the browser must download the compiled .wasm binary, which can be a large file. However, once downloaded, the execution is significantly faster than an equivalent amount of JavaScript. Figma uses caching and optimized loading strategies to ensure the initial boot time remains acceptable.
Can any browser run Figma's WebGL engine?
Most modern browsers (Chrome, Firefox, Safari, Edge) support both WebAssembly and WebGL. However, if a user has hardware acceleration disabled in their browser settings or is using a very old GPU that doesn't support the required WebGL version, Figma may fail to render or perform poorly.
How does Figma handle text rendering with WebGL?
Text is one of the hardest things to render in WebGL because it requires high precision. Figma uses a combination of techniques, including generating signed distance fields (SDFs) or using specialized glyph caches, to ensure that text remains crisp at any zoom level without needing to re-rasterize the font constantly.