Kayavak / The Web Frontend / FE·18 Browser Internals / Deeper
Deeper · The Web Frontend
Browser Internals
The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.
Why does this exist?
Early browsers were single programs: one crashing page, or one runaway script, took down every tab. In September 2008 Google released Chrome with a multi-process architecture, putting renderers in separate, sandboxed processes, and a new JavaScript engine, V8, that compiled JavaScript to machine code. Other browsers followed on both fronts: JIT-compiling engines (SpiderMonkey, JavaScriptCore) made heavy web applications possible, and process separation became standard.
The engines themselves have a lineage. Apple built WebKit (2001–03) from KDE's KHTML; Google forked WebKit into Blink in 2013. Mozilla's Gecko descends from Netscape. In 2018, after the Spectre attacks, Chrome turned on site isolation, a process per site, including cross-site iframes. Rendering moved work off the main thread too: a separate compositor thread scrolls and animates even while JavaScript runs.
The mental model
Try it yourself first: write your own model in the Mental Model Explorer, then compare.
A browser is several cooperating processes and threads. The main thread of each page does parsing, style, layout and your JavaScript in turn; anything that keeps it busy delays everything else on that list.
| Question | Answer |
|---|---|
| What is it? | A multi-process program that fetches, parses, styles, lays out, paints and composites pages, and runs their scripts |
| Problem it solves | Turning untrusted text from the network into interactive pixels, fast and safely |
| Parts | Browser, network, GPU and renderer processes; per page: parser, style, layout, paint, compositor, JS engine |
| How it works | URL → bytes → DOM and CSSOM → style → layout → paint → composite; scripts run between these steps on the main thread |
| Assumptions | Most frames need only some of the steps (a transform needs compositing only) |
| When they change | Changing geometry invalidates layout for many elements; long scripts delay every frame |
| Where it fails | Main-thread contention: one long task blocks input, rendering and parsing together |
| Related ideas | Processes and sandboxing (Foundations, ch08); JIT compilation (Foundations, ch10); performance (ch27) |
What if?
What if all tabs ran in one process?
Reason it through, then open
One crash or memory leak would take every tab with it, one hung script could freeze the whole browser, and a compromised page would share memory with your bank's page. That was the pre-2008 normal. Processes cost memory, which is why browsers balance isolation against footprint, for instance by sharing a process between pages of the same site.
What if animations ran on the main thread only?
Reason it through, then open
Any long JavaScript task would freeze scrolling and animations mid-motion. Because the compositor thread can move,
fade and scale already-painted layers without the main thread, animations of transform and opacity stay smooth
even while scripts run. Animating top or width needs layout, which only the main thread can do.
Where the boundary is
| Aspect | Main thread | Compositor thread |
|---|---|---|
| Does | Parsing, style, layout, paint recording, all page JavaScript | Combining painted layers into frames, scrolling, some animations |
| Blocked by | Long tasks | Rarely blocked by page code |
| Animate cheaply here | Nothing, if it can be avoided | transform, opacity |
| Confused because | Both are "the browser rendering" |
How sure are we?
| Claim | How it's known | Where from |
|---|---|---|
| Chrome launched in 2008 with multiple processes and V8 | Historical | Google's launch materials |
| Blink forked from WebKit in 2013 | Historical | Chromium announcement |
| Transform and opacity animations can avoid layout and paint | Measured | Browser documentation and the chapter's lab; varies with what else changes |
| The rendering pipeline's stages | Model | Engines differ in detail and keep moving work between threads |
Still open
Browser engine diversity is a concern in itself: almost every browser other than Firefox and Safari is built on Chromium. New engines (Ladybird, Servo's revival) are attempts to change that. Moving more rendering work off the main thread is ongoing.
What would change your mind? If a single-process design matched multi-process security and stability, the memory cost would no longer be worth paying. Spectre made that less likely, not more.
Recall
Why did Chrome use one process per tab or site?
To isolate crashes, hangs and security compromises, and later (site isolation) to defend against Spectre.
Which CSS properties can animate on the compositor thread?
transform and opacity.
What does a long JavaScript task block?
The main thread: input handling, style, layout, parsing and other scripts.
Which engines descend from KHTML?
WebKit, and Blink, which forked from WebKit in 2013.
Reflect
Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.