Performance: Pipe chaining
MEDIUM IMPACT
Pipe chaining affects the rendering speed and responsiveness by applying multiple transformations on data during template rendering.
Use a single custom pipe that combines all transformations or precompute values in the component: @Component({ ... }) export class MyComponent { transformedValue = this.combinePipes(this.value); combinePipes(val: any) { // combine logic of pipeA, pipeB, pipeC here return /* pipeC(pipeB(pipeA(val))) */ val; } } <!-- Template --> <div>{{ transformedValue }}</div>
<div>{{ value | pipeA | pipeB | pipeC }}</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple chained pipes in template | No extra DOM nodes | No reflows caused by pipes | Increased CPU paint cost due to multiple pipe executions | [!] OK |
| Single combined pipe or precomputed value | No extra DOM nodes | No reflows caused by pipes | Lower CPU paint cost due to fewer executions | [OK] Good |