completefrontend
Open lab My progress
THE WEB PERFORMANCE FIELD GUIDE

Inside the rendering engine

Follow one frame through Chrome's RenderingNG pipeline: which part of Chrome does each step, on which thread, and what it hands on. Then see how Firefox and Safari split the same work.

By the end, you can
  • 01
    Follow one frame through ChromeName the part of Chrome, the process and the thread for each step, from style to the screen.
  • 02
    Say what each step hands onComputed styles, the fragment tree, property trees, the display list, layers, tiles and the compositor frame.
  • 03
    Compare the three enginesSay how Firefox's WebRender and Safari's WebKit split the same work between their processes.

One change, from a script to the screen

Asha opens the Mint tea page on her phone. She taps Show details. A short paragraph appears under the price, and the Add to basket button moves down to make room. It happens faster than a blink.

Ravi built the page. From The pixel pipeline, he knows the steps: style, layout, paint and composite. The JavaScript course's The rendering pipeline shows them from a script's side. Now he wants to look one level deeper. Who inside Chrome does each step? On which thread, and in which process? And what does each step hand to the next one?

Chrome's team calls its way of drawing pages RenderingNG, short for the next generation of rendering. They wrote a series of articles about it, and Chrome's code is open. A frame is one picture on the screen. This lesson follows one real frame through both.

To record it, the course gave the Mint tea page a small test script. A second after the page loads, the script shows the details by itself, in one frame. It makes no other change. Chrome 157.0.8103.52 traced every process and thread while it ran. Here are five moments from the frame:

One frame, in five momentsPop out in the code editor (opens in a new tab)JavaScript
// One recorded frame of the Mint tea page, in ms after Chrome began it.const frame = { styled: 0.8, copied: 1.5, rastered: 2.1, drawn: 3.7, shown: 6 }; console.log(`The main thread started on the change at ${frame.styled} ms.`);console.log(`The compositor thread started its copy at ${frame.copied} ms.`);console.log(`A raster worker started on the tiles at ${frame.rastered} ms.`);console.log(`Viz started drawing the frame at ${frame.drawn} ms.`);console.log(`It was on the screen at ${frame.shown} ms.`);
  • Line 1 is a comment. Every time is in milliseconds (ms) after Chrome began the frame.
  • Line 2 holds five recorded times, one for each part of Chrome the change passed through.
  • Lines 4 to 6 print The main thread started on the change at 0.8 ms., The compositor thread started its copy at 1.5 ms. and A raster worker started on the tiles at 2.1 ms.
  • Lines 7 and 8 print Viz started drawing the frame at 3.7 ms. and It was on the screen at 6 ms.

You met the main thread and the compositor thread in Processes and threads. Both live in the page's renderer, the process that runs one site. Viz, short for visuals, is the part of Chrome that puts frames on the screen. It lives in a separate process, the GPU process. RenderingNG's articles call it the Viz process. Here is the whole frame, step by step, next to what Asha saw:

One recorded frame of the Mint tea page, in ms after Chrome began it. On the renderer's main thread, Blink runs style, layout, pre-paint, paint and layerize, from 0.8 ms to 1.4 ms. It hands the layers to the renderer's compositor thread, which commits, rasters, activates and draws, from 1.5 ms to 3.6 ms. It hands a compositor frame to Viz in the GPU process, which aggregates, rasters the tiles on the GPU and swaps, from 3.7 ms to 6.2 ms. The frame was on the screen at 6 ms. Beside the steps, two real frames: before the change, and after it, with the details shown and the button moved down.Renderermain thread0.8 to 1.4 msStyleLayoutPre-paintPaintLayerizeRenderercompositor thread1.5 to 3.6 msCommitRasterActivateDrawGPU processViz3.7 to 6.2 msAggregateGPU rasterSwaplayersa framepixelsbefore12.5 ms beforeThe Mint tea card before the change: the photo, the price, and the Add to basket button under the priceafterat 8.8 msThe Mint tea card after the change: a paragraph of details under the price, and the button moved down below it
Five steps on the main thread, four on the compositor thread, three in the GPU process. The shaded step runs on raster workers, the compositor thread's helpers. The two screens are real frames Chrome captured, just before and just after the change.

Three places, one after another. The main thread was done after 1.4 ms. Yet the frame reached the screen at 6 ms. Most of its trip happened on other threads. That's why it matters: the main thread is only the first stop.

Real-life analogyA newspaper's night shift

At night, a newspaper's newsroom writes the stories and lays out each page. It sends a copy of the pages to the print room, and starts on tomorrow's news. The print room makes the printing plates. The packing room puts the sports section, the ads and the front page into one paper. Then the paper goes out.

In real life: The newsroom, writing and laying out the pages
In Chrome: Blink, on the renderer's main thread
In real life: A copy of the finished pages, sent to the print room
In Chrome: The commit, to the compositor thread
In real life: The print room, making the printing plates
In Chrome: cc: raster and the compositor frame
In real life: The packing room, putting every section into one paper
In Chrome: Viz, putting every frame together
In real life: The paper on Asha's doorstep
In Chrome: The frame on Asha's screen
The main idea

Blink works out the page on the main thread: style, layout, pre-paint, paint and layerize. The compositor thread copies the result, rasters it and draws a compositor frame. Viz, in the GPU process, puts every frame together and shows it. Each step hands the next one a smaller, simpler thing than it got.

Style, layout and pre-paint: Blink works out the page

Blink is the part of Chrome that runs web pages inside the renderer. Its share of a frame is called the document lifecycle: a fixed list of states the page moves through. Chrome keeps the list in one file, document_lifecycle.h. In C++, the language Chrome is written in, an enum is a list of names. Lines that start with // are comments:

Blink's lifecycle states, shortened from document_lifecycle.h lines 55 to 76C++
kVisualUpdatePending,kInStyleRecalc,kStyleClean,kInPerformLayout,kLayoutClean,// In InPrePaint step, any data needed by painting are prepared.// Paint property trees are built and paint invalidations are issued.kInPrePaint,kPrePaintClean,// In InPaint step, paint artifacts are generated and raster invalidations// are issued.// In CAP, composited layers are generated/updated.kInPaint,kPaintClean,

In plain words, line by line:

  1. Line 1: something changed, and Blink waits for its turn to make a frame.
  2. Lines 2 and 3: working out style, then style is done. Chrome calls a finished step "clean".
  3. Lines 4 and 5: layout, then layout is done.
  4. Lines 6 and 7 are Chrome's comment: pre-paint gets ready for paint. It builds the property trees and marks what must be painted again.
  5. Lines 8 and 9: pre-paint, then pre-paint is done.
  6. Lines 10 to 12 are the comment for paint. Paint makes the display list. The last line says the layers are made here too. CAP is Composite After Paint, the project that moved that choice after paint.
  7. Lines 13 and 14: paint, then paint is done.

The BlinkNG article explains why the list matters. Each step's result is fixed once the step ends. Nothing may change it until the next frame. And there are only two ways into the pipeline: a full update for a new frame, or a quick answer to a question like offsetTop. That second way is the forced layout from Layout and layout thrashing. Step through the states yourself:

Playground: one frame through Blink's lifecycle
document_lifecycle.hstate 1 of 9
  1. kVisualUpdatePending
  2. kInStyleRecalcUpdateLayoutTree
  3. kStyleClean
  4. kInPerformLayoutLayout
  5. kLayoutClean
  6. kInPrePaintPrePaint
  7. kPrePaintClean
  8. kInPaintPaint, Layerize
  9. kPaintClean
Step 1 of 9
kVisualUpdatePending, line 55

Something changed. Blink has asked for a frame, and waits for the compositor thread's signal to start.

The states are document_lifecycle.h's, in its order. The times are from the recorded frame that showed the details, in ms after Chrome began the frame.

What each step hands on

  • Style works out each element's computed style: the final value of every CSS property. In the recorded frame, it restyled 2 elements. The trace calls this step UpdateLayoutTree.
  • Layout works out each box's size and place. Its result is the fragment tree, one fragment for each box. The data structures article says each fragment "becomes immutable and is never changed again". Immutable means fixed. In the recorded frame, 6 of the page's 19 layout objects needed layout. The rest kept their old results.
  • Pre-paint builds the property trees. There are four: transform, clip, effect and scroll. They say how each element is moved, cut off, faded, or scrolled. Pre-paint also marks what has to be painted again, in one walk over the layout tree.
Real-life analogyPlanning a school play

Before a school play, the teachers plan in order. First the costume sheet: what each actor wears. Then the stage plan, in pen: where each actor stands. Then the lighting plan: who stands on the turning stage, who stands behind the thin curtain, who stands in the dim corner. They also note which scenes changed since last night.

In real life: The costume sheet for each actor
In Chrome: The computed style of each element
In real life: The stage plan with chalk marks, drawn in pen
In Chrome: The fragment tree: sizes and places, never changed again
In real life: The lighting plan: who stands on the turntable, behind the gauze, under the dimmer
In Chrome: The property trees: transform, clip, effect, scroll
In real life: Notes on which scenes changed since last night
In Chrome: Paint invalidation: what must be painted again

Why it matters: these three steps run on the main thread, in this order, whenever something changes size or place. A script that keeps the main thread busy holds them back.

Paint, layerize and commit: a list, some layers, a copy

Paint doesn't make pixels. It writes a display list: drawing commands such as "fill this rounded rectangle green". Chrome's notes call it a "paint artifact", a list of display items in paint order. Items that share the same property trees are grouped into paint chunks.

You can see the real list. DevTools' paint profiler shows each layer's commands. The course read them on the visit that darkened the button. Pick a layer, then compare before and after:

Playground: a layer's drawing commands
The page17 commands
  1. 1Start with a clear layer. drawPaint
  2. 2Fill a 412 by 823 rectangle at 0, 0 with #FBF8F1. drawRect
  3. 3Fill a 412 by 48 rectangle at 0, 0 with #2F5D46. drawRect
  4. 4Draw a line of text at 16, 30 in #FFFFFF. drawTextBlob
  5. 5Fill a 378 by 409 rounded rectangle at 17, 65 with #FFFFFF. drawRRect
  6. 6Draw a 2 px rounded border, 378 by 409, at 17, 65 in #24311F. drawRRect
  7. 7Draw a line of text at 34, 113 in #24311F. drawTextBlob
  8. 8Save the drawing settings. save
  9. 9Draw only inside a 344 by 229 rounded rectangle at 34, 136. clipRRect
  10. 10Save the drawing settings. save
  11. 11Scale what comes next by 0.48, and move it to 34, 136. concat44
  12. 12Draw the 720 by 480 photo. drawImageRect
  13. 13Go back to the saved settings. restore
  14. 14Go back to the saved settings. restore
  15. 15Draw a line of text at 34, 395 in #24311F. drawTextBlob
  16. 16Fill a 132 by 44 rounded rectangle at 34, 413 with #2F6B3A. drawRRect
  17. 17Draw a line of text at 50, 441 in #FFFFFF. drawTextBlob
Try it yourself
The page, before the button darkened

The page's layer is 412 by 823 CSS pixels. Its display list has 17 commands.

The commands are Chrome's own, as DevTools' paint profiler shows them for each layer, on the recorded visit that darkened the button. The plain words are the course's; the method names are Skia's. Positions are in CSS pixels.

The page's layer holds 17 commands. When the button darkened, only one of them changed. Paint keeps the last list, and reuses every item that would come out the same. That's why it matters: a small change costs paint very little.

Layerize: on the main thread, after paint

Next, layerize splits the display list into layers: pieces the compositor can draw and move on their own. Its input is the paint artifact, and its output is a list of layers with their property trees. Here is where it runs:

Layerize, shortened from local_frame_view.cc lines 3428 to 3494C++
DEVTOOLS_TIMELINE_TRACE_EVENT("Layerize", inspector_layerize_event::Data,                              frame_.Get());// Skip updating property trees, pushing cc::Layers, and issuing raster// invalidations if possible.if (paint_artifact_compositor_->TryFastPathUpdate(        paint_controller_persistent_data_->GetPaintArtifact())) {  return;}paint_artifact_compositor_->Update(    paint_controller_persistent_data_->GetPaintArtifact(),

In plain words, line by line:

  1. Lines 1 and 2 write a "Layerize" event into the trace. That's the name DevTools shows.
  2. Lines 3 and 4 are Chrome's comment: skip the work when it can.
  3. Lines 5 to 8: if only small things changed, a quick path updates the layers in place and stops.
  4. Lines 9 and 10: otherwise, read the paint artifact and rebuild the layers from it.

This code belongs to LocalFrameView, which runs on the main thread. The RenderingNG architecture article's diagram puts layerize on the compositor thread, after the commit. The BlinkNG article explains the gap: the diagram "shows layerization as being off the main thread, whereas currently it's still on the main thread". The code at the course's release agrees with BlinkNG. In every recorded frame, Layerize ran on the main thread, before the commit.

For the Mint tea page, layerize made five layers. Two of them draw something you can see: the page, and the swaying leaf. The leaf got its own layer because its transform is animating:

Paint writes the Mint tea page as drawing commands, not pixels. Chrome's paint profiler shows 17 commands for the page's layer, such as command 3, fill the header (0,0,412,48), command 12, draw the photo, and command 16, fill the button (34,413,132,44). The leaf's 2 commands sit in a layer of their own, 24 by 24, because its transform is animating. Layerize made two layers that draw: the page's, 412 by 823, and the leaf's.Paint: the display list2Fill the page3Fill the header12Draw the photo16Fill the button17Draw the button's textand 12 more, 17 in allFill the leafLayerize: the layers that drawThe page: 17 commands412 by 823The leaf: 2 commands24 by 24: its transform is animating
Paint writes commands, and draws nothing yet. Layerize groups them into layers. The leaf's commands get a layer of their own, so the compositor can turn it without the main thread.

Commit: a copy for the compositor thread

The layers live on the main thread, and the main thread is about to start on other work. So the commit copies the layers and property trees to the compositor thread. How cc Works says commit pushes them into the pending tree: the compositor thread's own copy, waiting for raster. (cc is the folder of Chrome's code that runs the compositor.) Does the main thread wait while it's copied? Here is the main thread's side:

The commit, shortened from proxy_main.cc lines 337 to 565C++
bool blocking = block_on_next_commit_;block_on_next_commit_ = false;  ImplThreadTaskRunner()->PostTask(      FROM_HERE, base::BindOnce(&ProxyImpl::NotifyReadyToCommitOnImpl,  if (blocking)    layer_tree_host_->WaitForProtectedSequenceCompletion();

In plain words, line by line:

  1. Line 1: should the main thread wait this time? Read a flag called block_on_next_commit_.
  2. Line 2: set the flag back to false for the next frame.
  3. Lines 3 and 4: post a message to the compositor thread: "ready to commit".
  4. Lines 5 and 6: only if the flag was set, wait until the compositor thread has finished the copy.

Who sets the flag? A function for input. Chrome's comment says it: "If the next main frame will contain the visual response to an input event, we pause execution on the main thread". So the main thread waits only for frames that answer a tap or a key press. The How cc Works doc still says commit is done by blocking the main thread. The code at the course's release says otherwise, and the code wins.

The recording agrees. The test script made its change on its own, without a tap. The main thread handed off the commit and waited less than 0.01 ms. The compositor thread then spent 0.13 ms on the copy.

Real-life analogyOrders through a kitchen hatch

A cook writes each order as steps on a ticket. Dishes that leave the kitchen at different times go on separate trays. The cook passes a copy of the tickets through the hatch, then starts the next order. Only when a customer is waiting at the counter does the cook stop and watch the copy being taken.

In real life: The steps written on the order ticket
In Chrome: The display list
In real life: Dishes that leave at different times, on separate trays
In Chrome: Layers
In real life: A copy of the tickets, passed through the hatch
In Chrome: The commit, into the pending tree
In real life: Waiting while a customer stands at the counter
In Chrome: Waiting for the commit, on a frame that answers input

Raster and the display compositor: from tiles to the screen

The compositor thread now holds the layers, but still no pixels. Each layer is cut into tiles, pieces of the page. How cc Works says that with GPU raster, a tile is about as wide as the screen and a quarter as tall. Raster turns a tile's drawing commands into pixels. In this recording, that happened in two places:

  1. A raster worker, a helper thread in the renderer, took each tile. It handed the layer's display list to the GPU process, as commands. How cc Works calls this GPU raster.
  2. The GPU process's main thread ran those commands on the GPU, the graphics chip. That made the pixels.

The layout change needed 3 raster tasks, all on one worker thread. The GPU process ran 3 rasters for them.

Activate, then draw

New tiles take time. Meanwhile, the screen still needs frames: the leaf keeps swaying. So the compositor thread keeps two copies. The active tree is the one it draws from now. The pending tree waits. How cc Works says "The pending tree is the staging area to wait until all of the asynchronous rasterization work is complete." When its tiles are ready, activation makes it the active tree. Then the whole change appears at once, never half drawn.

Real-life analogyDressing a shop window behind a curtain

A shop changes its window display behind a curtain. People walking by still see the old display. Only when every piece of the new one is in place does the shop open the curtain. Nobody sees half a display.

In real life: The new display, set up behind the curtain
In Chrome: The pending tree, waiting for raster
In real life: The old display, still on show
In Chrome: The active tree, still drawn every frame
In real life: Opening the curtain once every piece is in place
In Chrome: Activation

Then the compositor thread draws. In cc, to draw means to build a compositor frame: a list of quads, rectangles that say where each tile goes, grouped into render passes. No pixels move yet. The compositor thread sends the frame to Viz. In the recorded frame, it held one render pass.

Viz puts every frame together

The page is not the only thing on Asha's screen. The browser's own bar at the top sends frames too. So does every iframe from another site. The architecture article says there is "exactly one Viz process for all of Chromium", as there is usually one GPU and one screen. Inside Viz, the display compositor combines them all. Here is its main function:

Viz draws one frame, shortened from display.cc lines 775 to 1134C++
bool Display::DrawAndSwap(const DrawAndSwapParams& params) {  TRACE_EVENT0("viz", "Display::DrawAndSwap");    frame = aggregator_->Aggregate(    renderer_->DrawFrame(&frame.render_pass_list, device_scale_factor_,    renderer_->SwapBuffers(std::move(swap_frame_data));

In plain words, line by line:

  1. Line 1: the function that makes one frame for the screen.
  2. Line 2: its trace event, Display::DrawAndSwap.
  3. Line 3: aggregate: put every compositor frame on the screen together into one.
  4. Line 4: draw it. Here, renderer_ means Viz's own drawing code, not a renderer process.
  5. Line 5: swap: hand the finished picture to the screen.
Real-life analogyA TV control room

During a live match, a TV control room gets pictures from many cameras. The mixing desk puts the score in one corner and the match in the middle, as one picture. Then that one picture goes on air.

In real life: Each camera's picture
In Chrome: Each compositor frame: the page, an iframe, the browser's bar
In real life: The mixing desk, putting the pictures into one
In Chrome: Aggregation in Viz's display compositor
In real life: Putting the picture on air
In Chrome: Draw and swap

Here is the recorded frame on all five threads, to scale:

The recorded layout frame on five threads, from 0 to 6.5 ms. Main thread: the script at 0.2 ms, then Blink's steps from 0.8 ms to 1.4 ms. Compositor thread: the commit at 1.5 ms, then activate and draw from 3.3 ms to 3.6 ms. Raster worker: 3 raster tasks from 2.1 ms to 3.3 ms. Viz compositor thread: aggregate and draw at 3.7 ms. GPU main thread: 3 rasters from 4.2 ms, then the swap at 5.3 ms. The frame was on the screen at 6 ms.Main threadCompositor threadRaster workerViz compositorGPU main threadscript, then style to layerizecommitactivate, draw3 raster tasksaggregate and draw3 rastersswapon the screen, 6 ms0 ms2 ms4 ms6 ms
Each bar is drawn to scale. The main thread was done after 1.4 ms. The other threads carried the frame the rest of the way. The GPU ran the three rasters before the swap.

One detail stands out. Viz started drawing at 3.7 ms. The GPU ran the three rasters at 4.2 ms, after that. Chrome doesn't make Viz wait for raster. The architecture article says it uses a "sync token" instead: a ticket the GPU checks, so it runs the raster before the draw. The swap came at 5.3 ms, and the frame was on the screen at 6 ms.

Here is every step of the recorded frame, with what it hands on. Read each row across:

Where each step runs, and what it hands on
StepWho runs it, and whereWhat it hands on
StyleBlink, on the renderer's main thread.A computed style for each element the change reached.
LayoutBlink, on the renderer's main thread.The fragment tree: each box's size and place.
Pre-paintBlink, on the renderer's main thread.Property trees, and marks on what must be painted again.
PaintBlink, on the renderer's main thread.The display list: drawing commands, grouped into paint chunks.
LayerizeBlink, on the renderer's main thread.A list of layers, and the compositor's own property trees.
Commitcc, on the renderer's compositor thread.A copy of the layers, in the pending tree.
Rastercc's raster workers, then the GPU process.Tiles of pixels in the GPU's memory.
Activatecc, on the renderer's compositor thread.The active tree, ready to draw.
Drawcc, on the renderer's compositor thread.A compositor frame: render passes full of quads.
Aggregate and drawViz, in the GPU process.One frame for the whole screen, drawn and swapped.

Three changes, three paths

Not every change runs every step. The course recorded two more changes on the same page, each in its own visit. One darkened the button: a change of look. In the other, the script only noted the time, and the course followed the leaf's sway, a CSS animation of transform. Here is the rule, as a small model:

Which steps a change needs, as a small modelPop out in the code editor (opens in a new tab)JavaScript
// A small model of which steps a change needs, written for this lesson.function stepsFor(change) {  const steps = ["commit", "raster", "activate", "draw"];  if (change === "size or place") return ["style", "layout", "pre-paint", "paint", "layerize", ...steps];  if (change === "look") return ["style", "pre-paint", "paint", "layerize", ...steps];  return ["animate", "draw"]; // a transform or opacity animation the compositor runs} console.log(stepsFor("size or place").length);console.log(stepsFor("look").includes("layout"));console.log(stepsFor("compositor animation").join(" -> "));
  • Line 1 says what this is: a model written for the lesson, not Chrome's code.
  • Line 3 lists the steps after Blink: commit, raster, activate and draw.
  • Line 4: a change of size or place runs every step.
  • Line 5: a change of look, like a colour, skips layout.
  • Line 6: an animation the compositor runs needs only two steps on the compositor thread.
  • Lines 9 to 11 print 9, false and animate -> draw.

Now check the model against the three recorded frames:

Playground: three changes, one frame each
Show the details13 steps ran
Show the details: the Mint tea card before
-12.48 ms
Show the details: the Mint tea card after
8.75 ms

Two real frames: just before the change, and just after it.

StepWhere it ranStartedTook
ScriptRenderer, main thread0.18 ms0.55 ms
StyleRenderer, main thread0.75 ms0.09 ms
LayoutRenderer, main thread0.85 ms0.16 ms
Pre-paintRenderer, main thread1.04 ms0.19 ms
PaintRenderer, main thread1.25 ms0.07 ms
LayerizeRenderer, main thread1.35 ms0.05 ms
CommitRenderer, compositor thread1.51 ms0.13 ms
Raster (3)Renderer, raster worker2.11 ms1.14 ms
ActivateRenderer, compositor thread3.3 ms0.05 ms
DrawRenderer, compositor thread3.36 ms0.25 ms
Aggregate and drawGPU process, Viz compositor thread3.71 ms0.17 ms
Raster on the GPU (3)GPU process, GPU main thread4.23 ms0.1 ms
SwapGPU process, GPU main thread5.31 ms0.89 ms

Nothing was skipped.

Try it yourself
Show the details

The details paragraph appears, and the button moves down. The main thread ran style, layout, pre-paint, paint and layerize. 3 raster tasks ran. The frame was on the screen at 6.01 ms.

Each change was recorded five times in Chrome, on a phone-sized screen; this is the frame with the middle time to the screen. Times are in ms after Chrome began the frame. Skipped steps didn't run at all.

The darker button skipped layout and still reached the screen at 3.3 ms. The leaf's frame never touched the main thread. It was on the screen 1 ms after Chrome began it. Between the two leaf frames in the playground, 1.5 seconds apart, the compositor drew 90 frames. The main thread made none, and nothing was rastered.

That's why it matters. A change that only moves or fades a layer keeps going while the main thread is busy. That's the idea behind Compositor-friendly animation and Scrolling performance. A change that needs the main thread waits for it. That wait is the presentation delay of INP.

How Firefox and Safari split the same work

Chrome isn't the only engine with this design. The RenderingNG article says "Gecko and Webkit have also implemented most of the same architectural features", sometimes before Chromium. Gecko is Firefox's engine. WebKit is Safari's. The jobs are much alike. Where they run, and what crosses between processes, differs.

Firefox: WebRender

Mozilla's Rendering Overview walks through it:

  1. In the page's content process, Gecko works out style and layout. Its style engine, Stylo, works across all of the computer's cores at once.
  2. Layout builds a frame tree, and from it a display list.
  3. The display list is packed into a WebRender display list and sent to the GPU process. On systems without one, that work runs in Firefox's main process instead.
  4. There, WebRender turns it into a scene, cuts the scene down to what's visible, and sends commands to the GPU.

So WebRender has no separate paint step before compositing. Mozilla's post on WebRender describes it as "removing the distinction between paint and composite", like a game engine drawing a scene. It still saves work between frames: the overview says it keeps parts of the page as cached tiles, in groups it calls slices. Scrolling and zooming are handled in the GPU process too, by a part called APZ.

Safari: WebKit's layers

In WebKit, the page runs in a web content process. There, WebKit keeps a render tree for the page, and a layer tree for the parts that need layers of their own. WebKit's graphics docs say its layer class has a version for each kind of system. One is for Core Animation, Apple's system for drawing layers.

WebKit's code for Apple's systems has a remote layer tree. The web content process builds its layers for the UI process, the process that draws the app's window. The UI process receives each update and keeps each layer as a Core Animation layer. On Linux, WebKit's docs describe another way. A compositor thread inside the web process puts the layers together. Then it shares the finished frame with the UI process.

Three engines, side by side. Chrome: the renderer does style, layout and paint, and sends compositor frames to Viz in the GPU process, which aggregates, rasters and draws. Firefox: the content process does style, layout and the display list, and sends a WebRender display list to the GPU process, where WebRender builds a scene and draws it. Safari, on Apple's systems: the web content process does style, layout and the layers, and sends a layer tree to the UI process, which holds them as Core Animation layers.ChromeRendererstyle, layout, paintcompositorframesGPU process: Vizaggregate, raster, drawFirefoxContent processstyle, layout, display listWebRenderdisplay listGPU processWebRender: scene, drawSafariWeb content processstyle, layout, layersa layertreeUI processCore Animation layers
All three keep the page's own work in one process and hand something smaller to another. What they hand over is different: frames, a display list, or a layer tree.

Here are the three engines side by side. Read each row across:

One page, three engines
QuestionChromeFirefoxSafari (WebKit)
Where style and layout runBlink, on the renderer's main thread.The content process. Its style engine uses every core.WebKit, in the web content process.
What leaves that processRaster commands and compositor frames, to the GPU process.A WebRender display list, to the GPU process.With its remote layer tree, on Apple's systems: layers, to the UI process.
What the other process does with itViz puts every frame together into one, and draws it on the GPU.WebRender builds a scene from it, and sends commands to the GPU.The UI process turns each layer into a Core Animation layer.
A paint step before compositingYes: paint, then raster, then draw.No: WebRender draws from the display list.Yes: each layer is painted, then the layers are put together.

Why it matters: the same CSS can cost different work in each engine. A change that skips paint in Chrome may be drawn a different way in Firefox. So measure in each browser. For Chrome, use DevTools' rendering tools.

Which part of Chrome does it?

Each job below happens somewhere in the frame you followed. Sort it by where it runs:

Which part of Chrome does it?
  • Working out the button's computed style
  • Building the property trees
  • Splitting the display list into layers
  • Turning the leaf a little for the next frame
  • Copying the layers into the pending tree
  • Making the pending tree the active tree
  • Turning one tile's display list into GPU commands
  • Putting the page's frame together with every other frame on the screen
  • Running the commands that fill a tile with pixels
  • Swapping the finished frame onto the screen
Try it yourself
0 of 10 correct

Sort each job by the thread or process that does it.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Common mix-ups

  • "Paint makes the pixels." No. Paint writes drawing commands, the display list. Raster makes pixels later, in the GPU process.
  • "The compositor thread decides the layers." No. In Chrome's code, layerize runs on the main thread, right after paint. The architecture diagram shows a planned move.
  • "Every commit freezes the main thread." No. The main thread waits only on frames that show the response to input. Otherwise it hands the commit off and moves on.
  • "Each tab puts its own pixels on the screen." No. Every tab, iframe and the browser's bar send compositor frames to Viz. Viz puts them together and draws one frame.
  • "A CSS animation needs the main thread in every frame." No. The recorded leaf animation drew 90 frames in 1.5 seconds, with no main-thread frame at all.
  • "Firefox and Safari work just like Chrome." No. Firefox sends a WebRender display list to its GPU process. On Apple's systems, WebKit's remote layer tree sends layers to the UI process.

Practice exercises

Answer first, then use the hints.

Exercise 1 · Warm-upThe first three steps

What does this program print?

Starter codePop out in the code editor (opens in a new tab)JavaScript
// A small model of which steps a change needs, written for this lesson.
function stepsFor(change) {
  const steps = ["commit", "raster", "activate", "draw"];
  if (change === "size or place") return ["style", "layout", "pre-paint", "paint", "layerize", ...steps];
  if (change === "look") return ["style", "pre-paint", "paint", "layerize", ...steps];
  return ["animate", "draw"]; // a transform or opacity animation the compositor runs
}

console.log(stepsFor("look").slice(0, 3).join(" -> "));

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upAfter the main thread

    The recorded layout frame again. What does the last line print?

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    // The recorded layout frame, in ms after Chrome began it.
    const frame = { mainDone: 1.4, shown: 6 };
    
    const more = (frame.shown - frame.mainDone).toFixed(1);
    console.log(`After the main thread was done, the frame took ${more} ms more.`);

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeRaster for a colour

      When the button darkened, how many raster tasks ran?

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeThe command that changed

        After the button darkened, what colour does the changed command fill with?

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeWhy the leaf has a layer

          Open the course's copy of the Mint tea page in Chrome, then DevTools' Layers panel. What reason does it give for the leaf's layer?

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeA busy main thread

            A script keeps the main thread busy for 300 ms. Which of the three recorded changes still reaches the screen during that time?

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, ask where the work happens: on the main thread, on the compositor thread, or in the GPU process.

              The rendering engine quiz · 8 questionsScore: first tries count
              1. Question 1 of 8What does the second line of the steps model print?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                // A small model of which steps a change needs, written for this lesson.
                function stepsFor(change) {
                  const steps = ["commit", "raster", "activate", "draw"];
                  if (change === "size or place") return ["style", "layout", "pre-paint", "paint", "layerize", ...steps];
                  if (change === "look") return ["style", "pre-paint", "paint", "layerize", ...steps];
                  return ["animate", "draw"]; // a transform or opacity animation the compositor runs
                }
                
                console.log(stepsFor("size or place").length);
                console.log(stepsFor("look").includes("layout"));
                console.log(stepsFor("compositor animation").join(" -> "));

                Choose an answer to see the explanation.

              2. Question 2 of 8In Chrome's code at the course's release, which thread runs Layerize?

                Choose an answer to see the explanation.

              3. Question 3 of 8What does the commit copy, and where to?

                Choose an answer to see the explanation.

              4. Question 4 of 8In the recording, where were the tiles' pixels actually made?

                Choose an answer to see the explanation.

              5. Question 5 of 8Why does the compositor thread keep a pending tree as well as an active tree?

                Choose an answer to see the explanation.

              6. Question 6 of 8What does Viz's display compositor do with the compositor frames it receives?

                Choose an answer to see the explanation.

              7. Question 7 of 8In Firefox, where does WebRender turn the page into GPU commands?

                Choose an answer to see the explanation.

              8. Question 8 of 8When does Chrome's main thread wait for the commit to finish?

                Choose an answer to see the explanation.

              Key takeaways

              • Blink runs style, layout, pre-paint, paint and layerize on the renderer's main thread, in that fixed order.
              • Each step hands on something simpler: computed styles, the fragment tree, property trees, the display list, then layers.
              • The commit copies the layers to the compositor thread. The main thread waits only on frames that answer input.
              • Raster workers send drawing commands to the GPU process. Activation shows the new tiles all at once. The draw builds a compositor frame.
              • Viz puts every compositor frame together, draws it on the GPU, and swaps it onto the screen.
              • Firefox sends a WebRender display list to its GPU process. Safari sends layers to its UI process.

              Remember the one-liner.
              Blink works the page out, cc copies, rasters and draws it, and Viz puts every frame together on the screen.

              Sources

              The facts on this page come from these articles, docs and source files. Chromium's are at the release the course records with:

              Coming next: How the metrics are computed. You've seen when a frame reaches the screen. Next, how Chrome turns those moments into LCP, INP and CLS.

              CompleteFrontend Clear concepts. Working examples.