Performance: Template expressions and statements
MEDIUM IMPACT
This affects how quickly Angular evaluates and updates the UI during change detection, impacting interaction responsiveness and rendering speed.
<div>{{ cachedValue }}</div>
// In component:
ngOnInit() {
this.cachedValue = this.complexCalculation();
}<div>{{ complexCalculation() }}</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Method call in template expression | Minimal DOM ops | Triggers reflows if result changes | Medium paint cost due to frequent updates | [X] Bad |
| Cached property binding | Minimal DOM ops | Single reflow on value change | Low paint cost | [OK] Good |
| Heavy logic in event handler | No DOM ops initially | Blocks reflow and paint during execution | High paint cost due to blocking | [X] Bad |
| Asynchronous event handling | No DOM ops initially | Non-blocking reflows and paints | Low paint cost | [OK] Good |