Skip to content

[Performance Increase] use $scope.on('$destroy') to cancel timeouts #6977

Open
@NightlyFox

Description

@NightlyFox

When scrolling horizontally/vertically sometimes a $scope is created and almost immediately destroyed before the DOM can even render the data generated from that $scope.

This results in a lot of $timeout functions still being ran even after the $scope of the cell/column/row has already been destroyed.

You can see many timeouts happening as you are scrolling through the grid if you use chromes performance tracker. Below is a snippet of all of them happening. Each one takes one average 200ms to complete.

image

When looking through the un-minified version of ui-grid i found many timeouts that were just set, and forgotten about.
By using $scope.on('$destroy') to cancel any timeouts created, this should improve scroll performance by canceling the timeout before it is ran, instead of wasting performance on executing timeouts on scopes that have already been destroyed.

This is a good article to read about timeouts, and how they should always be canceled in destroy events as to avoid potential problems.
https://www.bennadel.com/blog/2548-don-t-forget-to-cancel-timeout-timers-in-your-destroy-events-in-angularjs.htm

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions