I'm trying to optimize the performance of code in angular application.
I know that I can runOutsideAngular
some code in order not to cause change detection on each code run or event.
However, do I need to use runOutsideAngular
when I utilize OnPush
change detection strategy? (for listeners etc)
I think I have an answer now.
In my opinion it depends on what an app looks like.
If it has lots of unoptimized components and the an async operation is going to fire lots of times or it's an event listener then it has to be within runOutsideAngular
However, if an application is mostly built with components with OnPush
strategy or simply AppComponent
uses OnPush
(as whole tree is going to be using OnPush
strategy defining it on a top level component defines this strategy for the whole application irreversibly) then you can omit using runOutsideAngular
as triggers for change detection won't affect anything
Also I think that there is an option for fully OnPush
optimized app to disable all events patches from Zone thus there would be no need for runOutsideAngular
as all async events have no point of triggering NgZone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With