Performance: Why change detection matters
HIGH IMPACT
Change detection impacts how fast the page updates after user actions or data changes, affecting interaction responsiveness and visual stability.
import { Component, ChangeDetectionStrategy } from '@angular/core'; @Component({ selector: 'app-root', changeDetection: ChangeDetectionStrategy.OnPush, template: `<div>{{ counter }}</div><button (click)="increment()">Increment</button>` }) export class AppComponent { counter = 0; increment() { this.counter++; } }
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: `<div>{{ counter }}</div><button (click)="increment()">Increment</button>` }) export class AppComponent { counter = 0; increment() { this.counter++; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Default Change Detection | Many unnecessary checks | Multiple reflows per event | High paint cost due to frequent updates | [X] Bad |
| OnPush Change Detection | Checks only when needed | Single or minimal reflows | Lower paint cost with fewer updates | [OK] Good |