Performance: Why reactivity drives UI updates
HIGH IMPACT
This concept affects how quickly the UI updates in response to data changes, impacting interaction responsiveness and visual stability.
let count = 0; $: doubled = count * 2; function increment() { count++; } <!-- In markup --> <p id="count">{count}</p> <p>Doubled: {doubled}</p>
let count = 0; function increment() { count++; // Manually update DOM elements or force full component re-render document.getElementById('count').textContent = count; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual DOM updates on data change | Multiple direct DOM writes | Multiple reflows per update | High paint cost due to layout thrashing | [X] Bad |
| Svelte reactive variables with $: syntax | Minimal DOM updates only where needed | Single reflow per update | Low paint cost with efficient batching | [OK] Good |