awesome-everything RU
↑ Back to the climb

Browser & Frontend Runtime

DevTools flame strip and the frame lifecycle

Crux How to read a Performance flame strip, what contain/content-visibility do, the exact order of events inside one frame, and how microtasks differ from tasks.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at middle altitude — in the sky
◷ 16 min

You open DevTools Performance, record a scroll, and see a sea of coloured bars. Some bars are red. Most are yellow. You know jank is somewhere in there — but you don’t know which bar to fix. The flame strip is a map. This lesson teaches you to read it.

Reading the DevTools Performance flame strip

Open DevTools → Performance, click record, do whatever caused the jank, stop recording.

Track colours (Main thread):

  • Yellow — scripting (JavaScript executing)
  • Purple — rendering (style recalc + layout)
  • Green — paint
  • Dark blue — compositing

Track colours (Frames):

  • Green — on-time frame
  • Yellow — late frame
  • Red — dropped frame

The flame strip stacks calls top-down: the top bar is what JS triggered; each bar below is what that called. Find a long bar in red or yellow — that is your bottleneck. Hover to see exact ms.

Common DevTools patterns → diagnosis

Yellow JS bar → purple Layout bar

JS triggered a forced synchronous layout. The most common render-performance bug.

Wide purple Recalculate Style after a class change high in the tree

You cascaded style invalidation to too many descendants. Move the class change lower or use contain: style.

Wide green Paint after filter: blur(…) change

You exceeded paint complexity. filter is paint-heavy because each pixel requires multi-pixel sampling.

Wide dark-blue Composite Layers when nothing else looks wrong

Too many layers, often from will-change abuse. Audit with Layer Borders.

The frame lifecycle: exact order

Inside one frame the browser runs work in a strict order defined by the HTML spec:

  1. Collect input events (mousemove, keypress)
  2. Run setTimeout / setInterval callbacks if their time has elapsed
  3. Run microtasks (promise resolutions) until the queue is empty
  4. Run requestAnimationFrame callbacks
  5. Run ResizeObserver and IntersectionObserver callbacks
  6. Compute style and layout
  7. Paint
  8. Composite

After step 8 the browser yields to the OS and waits for the next vsync.

Crucial property: rAF runs before style/layout, so a write inside rAF is followed by exactly one layout pass for the frame — that is the entire purpose of rAF. ResizeObserver fires after layout but before paint; you can react to layout changes without triggering another forced layout. IntersectionObserver fires asynchronously across frames, never blocking the current one.

Microtasks vs tasks: scheduling boundaries

The microtask queue (promises, queueMicrotask) drains to empty between every step of the event loop, including between rAF callbacks.

A misbehaving promise chain that schedules itself indefinitely starves rendering — the browser cannot reach step 6 until the queue empties. This is why long promise chains and tight await loops appear in DevTools as a single uninterrupted yellow scripting bar, not a series of small ones.

Modern code that wants to yield to the renderer mid-task uses:

  • scheduler.yield() (Scheduler API, Chrome 115+) — designed specifically for this
  • setTimeout(fn, 0) — drops work onto the macrotask queue and unblocks rendering

Reactive frameworks and the pipeline

When React re-renders, DOM updates happen on the main thread, then the pipeline runs style and layout on changed nodes. Reconciliation itself is pure JS — it shows up as yellow in DevTools. If your re-render touches a node near the top of the tree, style invalidation cascades down the tree; if it touches an isolated leaf, the invalidation is local.

Key practice: keep state local, as close to the leaf as possible. A useState in a leaf component invalidates one node; a useContext on a top-level provider can invalidate hundreds. The same principle applies to Svelte stores, MobX observables, Vue refs — every reactivity model eventually writes to the DOM, and a DOM write triggers the same pipeline.

Why this works

Understanding the frame lifecycle order is what separates “scheduling tricks that work” from “scheduling tricks that quietly thrash.” A common mistake: writing a CSS property inside setTimeout(fn, 0) expecting it to batch with rAF-driven writes. It does not — setTimeout fires at step 2, before rAF at step 4, so the write happens one step before the rAF writes and cannot be batched together. Always put visual writes inside rAF, not macrotask callbacks.

Order the steps

Drag the events into the order they happen inside one frame, according to the HTML spec's rendering steps.

  1. 1 Browser processes input events (mousemove, keypress)
  2. 2 setTimeout / setInterval callbacks fire if due
  3. 3 Microtasks drain (promise.then handlers)
  4. 4 requestAnimationFrame callbacks run
  5. 5 ResizeObserver / IntersectionObserver callbacks fire
  6. 6 Style and layout are computed
  7. 7 Paint runs on the main thread
  8. 8 Compositor thread assembles and ships the frame
Quiz

In the DevTools Performance panel, a yellow JS bar is immediately followed by a purple Layout bar of similar length. What happened?

Quiz

An infinite `await` loop in a promise chain runs for 200 ms. What does the DevTools Performance panel show?

Quiz

You want to read the new size of a resized element and update a sibling's style in response. Which observer fires at the right time to avoid triggering a second layout?

Recall before you leave
  1. 01
    In what order do these fire inside one frame: rAF, setTimeout, microtasks, ResizeObserver, style/layout?
  2. 02
    Why does an infinite promise chain starve rendering?
  3. 03
    What colour are layout bars in the DevTools Performance panel, and what colour are scripting bars?
Recap

The DevTools Performance panel encodes pipeline stages as colours: yellow for JS, purple for layout/style, green for paint, dark blue for composite. The frame lifecycle is fixed by the HTML spec — rAF fires before style/layout, ResizeObserver after layout before paint. Microtasks drain completely between every step, so an infinite promise loop starves the renderer. To yield mid-task use scheduler.yield() (Chrome 115+) or setTimeout(fn, 0). Reactive frameworks trigger the same pipeline on DOM writes; keeping state local to leaf components minimises style-invalidation cascade.

Connected lessons
appears again in143
Continue the climb ↑Layout thrash: forced synchronous layout
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.