Skip to content

[Performance] ScrollDispatcher should subscribe lazily, and destroy subscriptions when they are no longer used #3237

Closed
@kasperhhk

Description

@kasperhhk

ScrollDispatcher needs to create subscriptions to the window scroll/resize events lazily (when they are actually needed by the UI) and destroy them once the UI using them gets destroyed.

Currently it simply subscribes to the scroll and resize events on init, which is when the page loads.
Since it is not utilizing the zone.runOutsideAngular functionality, then it means that every time a scroll or resize event happens, it will re-render the UI several times.

This usually goes unnoticed in smaller applications, but when you have bigger applications, this slows down the UI a lot.
It also removes performance control from the developers.

It's fine to emit the events when the dispatcher is actually being used by an overlay or whatnot, but it makes no sense to trigger zone to re-render the view every time the user scrolls, when there's nothing new to re-render.

I'd suggest making the subscriptions lazy and destroy them when components unsubscribe, or if possible using the zone.runOutsideAngular functionality to never trigger a re-render in the first place.

version 2.0.0-beta.2

Metadata

Metadata

Assignees

Labels

P2The issue is important to a large percentage of users, with a workaround

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions