You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In your pub/sub model you are broadcasting on the root scope, which bubbles down through every scope in the app (it's easy to have hundreds) looking for listeners.
You can achieve the same architecture with much better performance by using $rootScope.emit(...) rather than $rootScope.broadcast(....) On the listening side you'll need to change $scope.on(...) to $rootScope.on(...)
In my app the performance different was fairly huge in UI responsiveness, to the extent that I couldn't achieve my design until I made this modification.
In your pub/sub model you are broadcasting on the root scope, which bubbles down through every scope in the app (it's easy to have hundreds) looking for listeners.
You can achieve the same architecture with much better performance by using $rootScope.emit(...) rather than $rootScope.broadcast(....) On the listening side you'll need to change $scope.on(...) to $rootScope.on(...)
In my app the performance different was fairly huge in UI responsiveness, to the extent that I couldn't achieve my design until I made this modification.
See here for an explanation of avoiding .broadcast: http://stackoverflow.com/a/19498009/288703
and here for some quantification of the performance difference:
http://jsperf.com/rootscope-emit-vs-rootscope-broadcast
The text was updated successfully, but these errors were encountered: