Performance: Creating observables
MEDIUM IMPACT
This affects how quickly data streams start emitting and how efficiently Angular handles asynchronous data updates.
const obs = new Observable(observer => { const intervalId = setInterval(() => { observer.next(Math.random()); }, 1000); return () => clearInterval(intervalId); });
const obs = new Observable(observer => { setInterval(() => { observer.next(Math.random()); }, 1000); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Observable with no cleanup | 0 | 0 | 0 | [X] Bad |
| Observable with cleanup on unsubscribe | 0 | 0 | 0 | [OK] Good |