perf: run logic outside ngZone
See original GitHub issueI’m submitting a … (check one with “x”)
- bug report - search github for a similar issue or PR before submitting
- feature request
- support request - use StackOverflow (add the
ngx-charts
tag) or the gitter chat for support questions
Current behavior The mouseOver event runs inside the ngZone, which leads to hundreds of Angular check which impacts performance.
Expected behavior Some events must run outside the ngZone, only template changes should run inside the ngZone.
Reproduction of the problem https://stackblitz.com/edit/angular-ks78z1?file=src%2Fapp%2Fapp.component.html
What is the motivation / use case for changing the behavior? Perf matters.
-
ngx-charts version: 9.0.0
-
Angular version: 6.1.1
-
Browser: N/A
-
Language: N/A
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Running event listeners outside of the NgZone - InDepth.Dev
NgZone notifies Angular when to perform the change detection process (e.g. a DOM event with bound listener is one of the triggerers).
Read more >Angular - ngzone logic for inside vs outside - signalr sample
I have a simple application in angular >= 2 that uses signalr. I have a problem thou with understanding how to determine weather...
Read more >Zone.js and NgZone in Angular | Run your code outside Angular
Zone.js is responsible for the change detection in angular, angular has NgZone service which helps angular to automatically run the change ...
Read more >Adding Event Listeners outside of the NgZone - iFour Technolab
When we click the button, both the bound event listener and the change detection process are triggered. In a real-world scenario, instead of...
Read more >Using Zones in Angular for better performance
NgZone enables us to explicitly run certain code outside Angular's Zone, preventing Angular to run any change detection. So basically, handlers ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The event is not the problem, the problem is that it runs in the zone. One solution could be to register the event with regular js:
I don’t think there is a memory impact since no additional variables are used.
Even though the computation is a tiny bit more heavy, in the end you skip hundreds of change detection cycles.
@Ploppy3 @4ctarus https://github.com/swimlane/ngx-charts/issues/1162#issuecomment-510093587
workaround – I’ll be making a pull request from ngx-charts-extra later this month, need to further test possible side-effects as it’s a major change.