Performance: Reactive statements ($:)
MEDIUM IMPACT
Reactive statements affect how efficiently the UI updates when data changes, impacting interaction responsiveness and rendering speed.
let count = 0; $: doubled = count * 2; function increment() { count += 1; }
let count = 0; let doubled; function updateDoubled() { doubled = count * 2; } // Called manually after every count change function increment() { count += 1; updateDoubled(); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual update calls | Multiple updates triggered manually | Multiple reflows if UI updates after each call | Higher paint cost due to repeated changes | [X] Bad |
| Reactive statements ($:) | Single update triggered automatically | Single reflow per change | Lower paint cost due to batched updates | [OK] Good |