The Real Fullstack

The Layout Thrash

No network, no heavy maths, 60 ms API. Why does scrolling feel like wading through mud?

Ingénieur8 minLaboratoire de performanceLaboratoire de débogage
javascriptdomangularchrome-devtools

Ce défi n'est pas encore traduit en Français. Vous lisez la version anglaise.

Mission:Find what turns one layout per frame into three hundred, and restructure the code so the browser lays out the page once.Contexte · Objectifs d'apprentissage ▾

Fernpost's order table keeps row heights in sync while scrolling. A performance trace shows one 420 ms long task per scroll event, made of hundreds of alternating style recalculations and layouts.

Mission: Find what turns one layout per frame into three hundred, and restructure the code so the browser lays out the page once.

Objectifs d'apprentissage

  • Recognise forced synchronous layout (read after write).
  • Batch DOM reads before DOM writes.
  • Tell real fixes from hiding the symptom (debounce, will-change).
SimulationSimulé

Lancez la simulation pour voir la sortie.

Lancer la simulation
onScroll() {  // 1. read everything (one layout)  const heights = this.rows.map((row) => row.scrollHeight);  // 2. write everything in the next frame (no layout in between)  requestAnimationFrame(() => {    this.rows.forEach((row, i) => (row.style.height = heights[i] + 'px'));  });}/* .table { contain: layout; }  keeps the re-layout inside the table */

Simplification

Two symptoms with deterministic fixes. In a real trace you would confirm the fix by re-recording the performance profile. Modèle pédagogique — les chiffres illustrent un comportement, ce ne sont pas des benchmarks.

Concepts

Défis liés

Références