Performance: Derived values with $:
MEDIUM IMPACT
This affects how efficiently the UI updates when reactive data changes, impacting interaction responsiveness and rendering speed.
let count = 0; $: doubled = count * 2; // reactive declaration function increment() { count += 1; }
let count = 0; let doubled; function increment() { count += 1; doubled = count * 2; // manual update }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual updates of derived values | Multiple updates per change | Multiple reflows | Higher paint cost | [X] Bad |
| Using $: reactive declarations | Minimal updates, batched | Single reflow per change | Lower paint cost | [OK] Good |