Get up and running with ngx-performance-diagnostics in 5 minutes!
npm install ngx-performance-diagnostics --save-dev// app.component.ts
import {
CdMonitorPanelComponent,
MemoryLeakPanelComponent
} from 'ngx-performance-diagnostics';
@Component({
selector: 'app-root',
standalone: true,
imports: [
CdMonitorPanelComponent,
MemoryLeakPanelComponent
],
template: `
<router-outlet></router-outlet>
<ngx-cd-monitor-panel></ngx-cd-monitor-panel>
<ngx-memory-leak-panel></ngx-memory-leak-panel>
`
})
export class AppComponent {}// my-component.ts
import { ChangeDetectionMonitorDirective } from 'ngx-performance-diagnostics';
@Component({
selector: 'app-my-component',
imports: [ChangeDetectionMonitorDirective],
template: `
<div cdMonitor="MyComponent">
<h1>{{ title }}</h1>
</div>
`
})
export class MyComponent {
title = 'Hello World';
}# macOS
open -a "Google Chrome" --args --enable-precise-memory-info --expose-gc
# Windows
chrome.exe --enable-precise-memory-info --expose-gc- Open your app
- Click "Start" in Memory Panel (left)
- Wait 1-2 minutes
- Check for warnings
Component: 174.3 c/s ← BAD! (should be < 50)
Component: 8.2 c/s ← GOOD!
Trend: 5.67% /min ← LEAK! (should be < 2%)
Trend: 0.34% /min ← GOOD!
// Change from Default to OnPush
@Component({
changeDetection: ChangeDetectionStrategy.OnPush
})// Use takeUntil for subscriptions
private destroy$ = new Subject<void>();
ngOnInit() {
this.data$.pipe(takeUntil(this.destroy$)).subscribe(/*...*/);
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}Happy debugging! 🐛