Angular Labs
COOKIES
general / Use OnPush Change Detection

Use OnPush Change Detection

Optimize performance by using OnPush change detection strategy when possible

Description

Use OnPush change detection strategy to improve performance by reducing unnecessary change detection cycles.

When to use:

  • Components that receive data via @Input() - OnPush works best with immutable data patterns
  • Components that emit events via @Output() - Event handling automatically triggers change detection
  • Components with immutable data patterns - Ensures predictable change detection behavior
  • Performance-critical components - Reduces the number of change detection cycles

Benefits:

  • Improved Performance - Reduces unnecessary change detection cycles
  • Better Predictability - Makes change detection more explicit and controlled
  • Encourages Best Practices - Promotes immutable data patterns and reactive programming
  • Scalability - Essential for large applications with many components

When NOT to use:

  • Components that rely on mutable object properties changing
  • Components that need automatic detection of nested object changes
  • Simple components where performance is not a concern
  • Components that heavily use two-way data binding with mutable objects