I noticed that my Angular 2 application is getting a little slow after use.
I profiled the processor time and found out that there are massive change detection checks.
Processor profile immediately after page loading ...

... compared to the CPU profile after using the page for a while.

I used a lot of EventEmitter in different services to communicate between many components.
After testing for some time, it seems that the emitter for the window scroll event causes most of the large load.
Profile of the processor after using the page for some time without highlighting scroll events:

Here is the service implementation:
@Injectable() export class WindowService { @Output() scrolled$: EventEmitter<WindowScrolled> = new EventEmitter(); private scrollDebounceTime = 25; constructor() { this.addEvent(window, 'scroll', this.debounce((event) => { this.scrolled$.emit(new WindowScrolled(window.scrollX, window.scrollY)); }, this.scrollDebounceTime)); }
Questions
- How can I debug change detection calls to see where they apply?
- What else can cause so many change detection calls?
- If I use
EventEmitter , how to use it correctly?
Change 1
In addition, I place the grid tree component because the changes can be caused by the recursive tree structure that my components build.
@Component({ selector: 'hierarchy-grid-tree', moduleId: __moduleName,
The resulting hierarchical grid:

source share