Performance: Signal vs observable comparison
This concept affects how Angular apps handle data updates and UI rendering speed.
Jump into concepts and practice - no test required
const value = signal(initialValue); // Signal usage value.set(newValue); // Updates UI reactively with minimal overhead
this.data$.subscribe(value => { this.value = value; }); // Observable subscription in component
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Observable subscription with frequent updates | Multiple updates to DOM nodes | Multiple reflows per update | Higher paint cost due to broad changes | [X] Bad |
| Signal with direct reactive updates | Minimal DOM node updates | Single reflow per update | Lower paint cost with targeted changes | [OK] Good |
const count = signal(1); count.set(5); console.log(count());
const obs = new Observable(subscriber => {
subscriber.next(1);
});
obs.next(2);Option A: Use a signal to hold the counter value. Option B: Use an observable and subscribe to updates. Option C: Use a Promise to fetch the counter value. Option D: Use a BehaviorSubject without subscription.