Performance: Why signals are introduced
Signals improve how Angular tracks changes, reducing unnecessary work during rendering and speeding up user interactions.
Jump into concepts and practice - no test required
import { signal } from '@angular/core'; class MyComponent { data = signal([]); updateData(newData) { this.data.set(newData); // Only updates dependents of this signal } }
class MyComponent { data = []; updateData(newData) { this.data = newData; // Angular runs full change detection on all bindings } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full Angular Change Detection | Many nodes checked | Multiple reflows if many bindings update | High paint cost due to large updates | [X] Bad |
| Using Angular Signals | Only dependent nodes updated | Single or minimal reflows | Lower paint cost due to scoped updates | [OK] Good |
signal() to create a signal.const count = signal(0); count.set(5); console.log(count());
count starts at 0, then count.set(5) updates its value to 5.count() returns the current value, which is 5 after the update.const count = signal(0); count = signal(5);