Skip to content

broadcast is slow on apps of moderate size #4

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions