task: 180 ms(Long Task) Main h r Input click(20 ms)→ handler 開始(180 ms): 入力遅延 160 ms 0 ms 50 ms 100 ms 150 ms 200 ms h = handler, r = render。破線の vsync では frame を出せない(約 10 frame 落ち) • Long Task = main を 50 ms 以上占有する task • event loop は task を途中で奪わない(non-preemptive)。1 task の長さ = 応答遅延の下限 • 対策は 2 つだけ: 刻む(協調的スケジューリング)か、main から追い出す(Worker) Advanced Frontend Tech 6
N 回走らせる ✕ 交互: layout × N W R* W ◦ 分離: layout × 1 R* W R* for (const el of els) { el.style.width = calc(el) + "px"; total += el.offsetHeight; // flush } R R R W W W L const hs = els.map(el => el.offsetHeight); els.forEach((el, i) => { el.style.width = calc(el, hs[i]) + "px"; }); W = write, R = read, R* = forced layout を伴う read, L = frame 末尾の通常 layout 原則: 同じ frame 内で read を先に、write を後に。書いた結果は次の frame(rAF)で読む Advanced Frontend Tech 26
SPA) Local-first UI UI 即時 HTTP(RTT を待つ) Server Local DB background Sync Engine protocol DB Server Local state = primary / Remote = synchronization target 得るもの: 即時の操作感とオフライン動作 払うもの: 同期・競合・障害時の整合性 Advanced Frontend Tech 45
/ Atomics • MDN: Critical rendering path / Animation performance and frame rate • Chrome for Developers: Use scheduler.yield() to break up long tasks • Chrome for Developers: Long Animation Frames API • MDN: OffscreenCanvas / AudioWorklet / Long animation frame timing • web.dev: Optimize long tasks • MDN: IndexedDB API / Web Locks API / Broadcast Channel API • Figma Blog: Making multiplayer more reliable • MDN: FileSystemSyncAccessHandle / StorageManager.persist() / estimate() • Figma Blog: How Figma draws inspiration from the gaming world • W3C: Indexed Database API 3.0(transaction scheduling / lifecycle) • Figma Blog: Building Figma’s Code Layers Advanced Frontend Tech • Figma Blog: How Figma’s multiplayer technology works 61