angular-ui/ui-grid

Digest cycles initiated by the grid

Open

#5,007 建立於 2016年1月21日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)JavaScript (5,395 star) (2,496 fork)batch import
help wantedseverity: memory leakseverity: performance

描述

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?

貢獻者指南