Single-threaded C++ CSS engine (Gecko)⟶Quantum CSS / Stylo (Rust, parallel, ported from Servo)
Firefox's CSS engine matched selectors and computed styles for every DOM node on a single core. Quantum CSS, ported wholesale from Mozilla's experimental Servo browser, splits that work across every core on the machine — safely, because Rust can prove at compile time that there's no data race to find.
A CSS engine ported from a research browser, parallelized safely enough that hundreds of contributors don't have to personally verify it.
Project Quantum: replacing a jet engine mid-flight
Project Quantum is Mozilla’s major rewrite of Firefox’s internals, swapping in components from Servo — Mozilla’s experimental research browser — one piece at a time. Mozilla describes it as “replacing a jet engine while the jet is still in flight”: changes land in place, component by component, so users see the effects as soon as each piece is ready. The first major component to make that transfer is a new CSS engine called Quantum CSS, previously codenamed Stylo, and by the time of writing it’s available for testing in Firefox Nightly behind the layout.css.servo.enabled flag.
The CSS engine’s job is simple to state and expensive to run: for every node in the DOM, figure out which CSS rules apply, then fill in a value for every CSS property, whether or not a stylesheet actually sets one. That work doesn’t just happen once at page load — it re-runs on hovers, class changes, and DOM mutations, any time a “restyle” is triggered.
COMPLICATION
One core, doing this for every node, over and over
Browsers have spent twenty years testing strategies to speed style computation up, because a modern CPU has multiple idle cores sitting next to the one core the CSS engine is actually using to walk the DOM tree, node by node, in sequence.
QUESTION
How do you parallelize code you can't ask every contributor to reason about?
That’s the real constraint. It isn’t enough to parallelize the CSS engine once, carefully, in a lab. Mozilla ships changes to this code from hundreds or thousands of engineers, most of whom will never sit down and manually verify that their change doesn’t introduce a data race across threads. The question Quantum CSS has to answer is how to make parallel style computation safe enough that ordinary contributors can’t accidentally break it.
ANSWER
Work stealing, a rule tree, a style-sharing cache — and a compiler that catches data races
Quantum CSS answers with a stack of techniques combined from four different browsers. Work stealing splits each DOM node’s children into work units and queues them; when one core empties its queue, it steals work from another core’s queue instead of sitting idle, dividing the work evenly without walking the tree up front to plan it. The result, Mozilla reports, is close to linear speedup — “2 or 4 or even 18 times faster,” depending on the machine. On top of the parallelism, a rule tree (inherited from Firefox’s previous CSS engine) lets many restyles skip selector matching and sorting entirely, and a style-sharing cache — improved on the versions already in Safari and Chrome — lets DOM nodes with identical styles reuse an already-computed result instead of recomputing it.
TAKEAWAY
The first big transfer from a research browser to a shipping one
Quantum CSS is, in Mozilla’s own words, “the first big technology transfer of Servo tech to Firefox” — proof that code from an experimental research browser could be merged into one of the most complex, most contributed-to parts of a fifteen-year-old production rendering engine. At the time of publication it’s still opt-in on Nightly, one piece of Project Quantum’s jet-engine-in-flight rewrite.
Parallelism only becomes safe to hand to hundreds of contributors once the compiler — not code review, not discipline — is the thing refusing to let a data race compile.
Four separate C++-to-Rust rewrites inside Firefox, 2016 to 2022 — media parsing, the CSS engine, a security retrospective on that same rewrite, and the crash reporter. Same company, same language bet, four different fires.
A plain-language, AI-drafted and human-edited retelling of the article published on hacks.mozilla.org, reorganized and explained in our own structure and words, with original analysis in the editor's note above. The facts, numbers, and decisions belong to the original author and are not altered. For the full depth, read the source.