Performance: Reactive declarations (let)
MEDIUM IMPACT
Reactive declarations affect how efficiently the UI updates when data changes, impacting interaction responsiveness and rendering speed.
let count = 0; $: doubled = count * 2;
let count = 0; let doubled; function updateDoubled() { doubled = count * 2; } // called manually after count changes updateDoubled();
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual state update with functions | Multiple updates | Multiple reflows if not batched | Higher paint cost due to redundant changes | [X] Bad |
| Reactive declarations with $: | Single update per dependency change | Minimal reflows | Lower paint cost due to targeted updates | [OK] Good |