Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Optimize away broadcasts (and maybe emits) with no listeners #5341

Closed
@kseamon

Description

@kseamon

On my app's more complex pages with lots of nested scopes, $broadcast can become expensive, eating up 30ms for a $location change and 10-20 more if it results in a route change.

Most if not all of the events broadcasted in the process are not used by my app.

I propose the following two optimizations:

  1. Have scope.$on register that an event key has a listener. Short circuit $broadcast if there are no listeners for a given key.
    1a) Extra credit: store a "reference count" along with the registration and decrement it on scope.$destroy in order to keep the registry garbage collected.
  2. Note if a registration is on $rootScope. For events that have only been registered on $rootScope, there's no need to walk down the tree.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions