Performance: Pipe chaining
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 |
| to chain pipes in templates.| pipeName after the value.| symbols [OK]| symbols to chain pipes [OK]{{ 'angular' | uppercase | slice:0:3 }}uppercaseslice:0:3{{ 123 | uppercase | slice:0:2 }}uppercase usageuppercase pipe coerces the input to a string first (123 becomes '123'), then applies toUpperCase(), resulting in '123'.slice:0:2uppercase to convert all letters, then slice:0:5 to get first 5 characters.{{ userName | uppercase | slice:0:5 }} applies uppercase first, then slice, which matches the requirement.Pass the test and this pattern moves unknown