Performance: Input signals and model signals
MEDIUM IMPACT
This concept affects how Angular updates the UI in response to user input and data changes, impacting interaction responsiveness and rendering speed.
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-counter', standalone: true, template: ` <button (click)="increment()">Increment</button> <p>Count: {{ count() }}</p> ` }) export class CounterComponent { count = signal(0); increment() { // Batch updates by calculating new value first const newValue = this.count() + 5; this.count.set(newValue); } }
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-counter', standalone: true, template: ` <button (click)="increment()">Increment</button> <p>Count: {{ count() }}</p> ` }) export class CounterComponent { count = signal(0); increment() { // Directly mutating the signal multiple times in a loop for (let i = 0; i < 5; i++) { this.count.set(this.count() + 1); } } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple signal.set calls in loop | Multiple updates | Multiple reflows (equal to updates) | High paint cost | [X] Bad |
| Single batched signal.set call | Single update | Single reflow | Low paint cost | [OK] Good |