Performance: Computed signals for derived values
MEDIUM IMPACT
This affects how efficiently Angular updates the UI when derived data changes, impacting interaction responsiveness and rendering speed.
const count = signal(0); const multiplier = signal(2); const derivedValue = computed(() => count() * multiplier()); // UI automatically updates when derivedValue changes effect(() => { updateUI(derivedValue()); });
const count = signal(0); const multiplier = signal(2); // Manually using separate effects to update derived value let derivedValue = 0; effect(() => { derivedValue = count() * multiplier(); updateUI(derivedValue); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual separate effects for derived values | Multiple redundant DOM updates | Multiple reflows per dependency change | High paint cost due to repeated updates | [X] Bad |
| Computed signals for derived values | Single DOM update per change | Single reflow per change | Minimal paint cost with batched updates | [OK] Good |