angular-ui/ui-grid

Digest cycles initiated by the grid

Open

#5,007 opened on Jan 21, 2016

View on GitHub
 (3 comments) (0 reactions) (0 assignees)JavaScript (5,395 stars) (2,496 forks)batch import
help wantedseverity: memory leakseverity: performance

Description

There are way too many digest cycles for the grid load/rendering. I've managed to reduce the load by setting some of the $timeouts to $timeout(method, 0, false). I've managed to reduce the number by 2/3 this way, with no seeming side effects (and my app now loads much faster - I have around 9-10 grids on one page, that can open side menus with more, so this is critical...).

I've created a plnkr that shows that every load, you get roughly 35 digest cycles - with no extra feature involved: http://plnkr.co/edit/uOYKeJvANJu1b9zk8Ac1?p=catalogue (it also shows that the grid increases the number of digests each time it reloads which might indicate a memory leak, but then again, it might be just the demo app).

For instnace: https://github.com/angular-ui/ui-grid/blob/1dc9931f88d7b2183ae25d16df0ab6192cba997d/src/js/core/directives/ui-grid.js#L244 init is being called iniside a $timeout. It then calls grid.refreshCanvas which in turn does another $timeout (https://github.com/angular-ui/ui-grid/blob/a1e6a04ced73dfc4ef83000f5e44fc6aeec6d7b3/src/js/core/factories/Grid.js#L2121), hence calleing twich to a digest cycle...

As I said, I've managed to reduce this number of cycles with the method above. Is there a special reason why there are so many $timeouts inside the core code?

Contributor guide

Digest cycles initiated by the grid · angular-ui/ui-grid#5007 | Good First Issue