"매 VDOM diff = O(n) heuristic — 매 same-level node 의 비교 + key-based identity.". 매 React/Vue/Preact 모두 매 Levenshtein-style O(n³) 의 회피하기 위해 매 두 가정 (1) 다른 type = subtree 교체, (2) key가 child identity 의 hint. 매 React 19 (2024) Fiber + concurrent rendering, Vue 3.4 patchFlag-driven static hoist 의 진화.
매 핵심
매 두 가정 (Heuristics)
매 different element type ⇒ subtree 의 unmount + 재생성.
매 stable key ⇒ list reconciliation 의 identity hint.
매 알고리즘
React = Fiber tree, work loop가 매 cooperative scheduling 가능 (concurrent mode).
Svelte/Solid = 매 VDOM 없음 — 매 fine-grained reactivity 의 directly DOM 의 patch.
매 응용
Keyed list — 매 stable key가 매 reorder cost 의 minimize.
Conditional render — 매 ternary가 매 type swap 의 발생.
Concurrent rendering — 매 high-priority update가 매 low-priority interrupt.
💻 패턴
1. Stable key (correct)
// CORRECT — id is stable identity
items.map((item)=><Rowkey={item.id}item={item}/>)// WRONG — index changes when list reorders
items.map((item,i)=><Rowkey={i}item={item}/>)
2. Type swap forces unmount
{condition?<div>A</div>:<span>A</span>}// span/div type 다름 → subtree unmount + remount
// 같은 component reuse 원하면 같은 type 유지:
<div>{condition?'A':'B'}</div>
3. React Fiber priority lanes (19)
import{useTransition}from'react';const[isPending,startTransition]=useTransition();constonChange=(e)=>{setInput(e.target.value);// urgent
startTransition(()=>{setFilter(e.target.value);// can be interrupted
});};
4. Vue 3 patchFlag (compiled)
<!-- Source --><div><span>{{ msg }}</span><spanclass="static">hi</span></div><!-- Compiled (simplified) --><!-- 첫 span has patchFlag = 1 (TEXT) → diff only text --><!-- 두번째 span hoisted as static — 매 diff 건너뛰기 -->
5. Vue keyed list w/ LIS
<TransitionGrouptag="ul"><liv-for="item in items":key="item.id">{{ item.label }}</li></TransitionGroup><!-- Vue calculates LIS to minimize DOM moves -->
// Solid — fine-grained reactivity, no VDOM
import{createSignal}from'solid-js';const[count,setCount]=createSignal(0);// JSX compiles to direct DOM ops; only `count()` text node updates
return<div>count:{count()}</div>;
8. Avoid layout-impacting reorder
// Stable order with key — only reorder DOM, no remount
<>{sorted.map((u)=><UserCardkey={u.id}user={u}/>)}</>// Each UserCard preserves its instance (state, refs) on reorder.
매 결정 기준
상황
Approach
List render
매 stable id key — index X.
Heavy filter + input
useTransition + deferredValue.
Static UI
Vue patchFlag / React.memo.
Maximum perf
Solid / Svelte (skip VDOM).
Type-switch UI
wrap in same outer type to preserve children.
기본값: 매 React 19 + Suspense + Transition + 매 stable key.