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:
3
main.js
3
main.js
@ -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.
|
||||
|
Reference in New Issue
Block a user