The Real Fullstack

The Rendering Storm

Only one of 500 prices changed. Why did the browser rebuild 500 rows?

シニアエンジニア9 分パフォーマンスラボコード課題
angularsignalstypescriptreact

この課題はまだ日本語に翻訳されていません。英語版を表示しています。

ミッション:Make each tick cheap (≤ 2 ms of work) while the UI still shows the new price.背景 · 学習目標 ▾

Quillfin's watchlist shows 500 instruments. A websocket updates one price per tick. On mid-range laptops the fan spins up and scrolling stutters. A profiler shows change detection and DOM creation in every frame.

ミッション: Make each tick cheap (≤ 2 ms of work) while the UI still shows the new price.

学習目標

  • Explain what default change detection checks on every event.
  • Combine OnPush or signals with immutable updates.
  • Use stable track keys and memoised derived values.
シミュレーションシミュレーション値
tick
11 of 500 prices changes (array mutated in place)
change detection
2501 component checks
template
3total() evaluated 501× (20.0 ms)
DOM
41 row(s) re-created
シミュレーションを実行
@Component({  selector: 'app-watchlist',  template: `<p>Total: {{ total() }}</p>                 <!-- method re-run on every check -->    @for (q of quotes; track q) { <app-quote [quote]="q" /> }`,   // track by object identity})export class WatchlistComponent {  quotes: Quote[] = [];  total() { return this.quotes.reduce((s, q) => s + q.price * q.qty, 0); }  onTick(t: Tick) {    this.quotes = this.quotes.map((q) => (q.id === t.id ? { ...q, price: t.price } : { ...q })); // every item copied  }}

簡略化

Costs per check, per DOM row and per template call are fixed constants. Real costs depend on component size and browser. 教育用モデルです。数値は挙動を示すためのもので、ベンチマークではありません。

コンセプト

関連する課題

参考資料