Home
← All questions

Reflow, repaint, and compositing layers | Web Fundamentals

HardPremiumWeb Fundamentals

Asked at Google · Meta · Apple

Web Fundamentals interview practice: Explain layout thrashing and GPU compositing — critical for performance interviews.

Answer

After the render tree is built, the browser pipeline runs:

  1. Layout (reflow) — compute geometry (width, height, position). Triggered by geometry changes, font changes, window resize.
  2. Paint — fill pixels (color, text, shadows) into layers.
  3. Composite — GPU merges layers to screen.

Expensive pattern — layout thrashing:

// ❌ interleaved read/write forces sync layout each iteration
for (const el of elements) {
  el.style.width = box.offsetWidth + 10 + "px"; // read then write × N
}

Compositor-only properties (transform, opacity) skip layout/paint on change — ideal for animations.

Promotion to own layer: will-change: transform, transform: translateZ(0) — helps but overuse increases memory.

Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium