angularjs-spinner icon indicating copy to clipboard operation
angularjs-spinner copied to clipboard

broadcast is slow on apps of moderate size

Open ghost opened this issue 11 years ago • 0 comments

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

ghost avatar Mar 05 '14 00:03 ghost