Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broadcast is slow on apps of moderate size #4

Open
ghost opened this issue Mar 5, 2014 · 0 comments
Open

broadcast is slow on apps of moderate size #4

ghost opened this issue Mar 5, 2014 · 0 comments

Comments

@ghost
Copy link

ghost commented Mar 5, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants