question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve performance with ChangeDetectionStrategy

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here

Current behavior

A complex table (many rows/columns) will cause the browser to hiccup on Angular change detection, causing jerky animations and other performance issues.

Expected behavior

ngx-datatable should be optimized to do minimal Angular change detection.

Reproduction of the problem

I noticed this when I added a <md-input> (angular/material2), which has a floating label animation. With a ngx-datatable as a sister component, the animation is jerky. Also, do a Chrome Dev Tools JS CPU profile with and without ngx-datatable on a page. You will notice much more time spent in AppView.detectChanges.

Expand: AppView.detectChanges > ViewContainer.detectChangesInNestedViews and you will see many ngx-datatable detectChangesInternal calls.

What is the motivation / use case for changing the behavior?

ngx-datatable should have good performance in Angular.

  • Table version: 6.0.2
  • Angular version: 2.4.6
  • Browser: Chrome
  • Language: TypeScript 2.1.5

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
arlowhitecommented, Feb 9, 2017

I added changeDetection: ChangeDetectionStrategy.OnPush to DatatableComponent, but it didn’t improve performance much. So then I added OnPush to DataTableBodyComponent, DataTableBodyRowComponent, DataTableBodyCellComponent and performance improved significantly.

I was under the impression that only the root component would need OnPush, but this doesn’t seem to be the case. So maybe OnPush should be added to every ngx-datatable Component? I don’t have much experience on ChangeDetection optimization; I’ve just read a bit on it.

One problem with this is that users may need to change how they input data into ngx-datatable. To trigger an update to rows, they would need to change the reference (make a copy of rows array). Alternatively, rows could also be an Observable (any[] | Observable<any[]>); from what I’ve read Angular change-detection is Observable aware. Could also add a refresh() method or something, which triggers change detection, but this seems ugly to me in the Angular world.

Hopefully someone who has worked on ChangeDetection optimization knows the best way to design this.

0reactions
amcdnlcommented, Feb 15, 2017

I do with some of them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Performance improvement using change detection
Change detection is responsible to update the view (DOM) data when state data has changed. By default, when a state value in component...
Read more >
Better Angular performance with ChangeDetectionStrategy ...
In the application I'm currently working on, we've now started to implement these changes as a means to improve overall performance, especially ...
Read more >
How to improve the performance of your Angular app - Miquido
I have prepared a quick list of the most popular performance boost strategies and tips that may help you to instantly increase the...
Read more >
Improve Front-End Performance Using Angular Change ...
Improve Front-End Performance Using Angular Change Detection Strategy. Learn how to improve your performance using the change detection ...
Read more >
Mastering the Angular performance — by dropping the magic ...
Which means less magic, better performance, and much clearer error stack traces ;). TL;DR. Always use ChangeDetectionStrategy.OnPush . Try to divide your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found