Skip to content

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

Closed

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

Activity

  1. fxck commented on Feb 22, 2017

    @fxck
    Contributor

    I swear I saw a PR dealing with this already but can't seem to be able to find it now.. if not, this seems like a pretty big issue.

    @andrewseguin @crisbeto ?

  2. kara commented on Feb 22, 2017

    @kara
    Contributor

    Related to #3179.

  3. added
    P2
    on Feb 22, 2017
  4. added a commit that references this issue on Feb 23, 2017
    fae1529
  5. self-assigned this
    on Feb 23, 2017
  6. added a commit that references this issue on Mar 9, 2017
    c1004cb
  7. added a commit that references this issue on Apr 16, 2017
    ac476e4
  8. angular-automatic-lock-bot commented on Sep 5, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions