Avoid using Object.keys(obj).length in hot code paths

Complexity of Object.keys(obj).length is O(n) where n is the number of
object keys. Unfortunately, JavaScript have no built-in means of
determining number of object keys in constant time. Therefore, we have
to count object keys using separate counter variable.

It may look ugly (and indeed it is), but it greatly improves smoothness
and overall feel of IITC.
This commit is contained in:
Inye
2013-08-02 20:00:03 +04:00
parent 8563498ded
commit 55c055425b
5 changed files with 28 additions and 12 deletions

View File

@ -250,8 +250,11 @@ var portalsLayers, linksLayer, fieldsLayer;
// automatically kept in sync with the items on *sLayer, so never ever
// write to them.
window.portals = {};
window.portalsCount = 0;
window.links = {};
window.linksCount = 0;
window.fields = {};
window.fieldsCount = 0;
window.resonators = {};
// contain current status(on/off) of overlay layerGroups.