Performance: map operator for transformation
MEDIUM IMPACT
This affects how efficiently data streams are transformed before rendering, impacting interaction responsiveness and rendering speed.
this.transformedData$ = this.data$.pipe( map(data => data.map(item => fastCalculation(item))) ); // Async pipe in template handles subscription and rendering
this.data$.subscribe(data => { const transformed = data.map(item => { // heavy synchronous transformation return expensiveCalculation(item); }); this.renderData(transformed); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous transform in subscribe | Multiple updates if not batched | Multiple reflows if DOM updates triggered repeatedly | High paint cost due to blocking | [X] Bad |
| Using map operator inside pipe with async pipe | Single update per data change | Single reflow | Low paint cost, smooth rendering | [OK] Good |