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:
@ -5,9 +5,9 @@
|
||||
window.debug = function() {}
|
||||
|
||||
window.debug.renderDetails = function() {
|
||||
console.log('portals: ' + Object.keys(portals).length);
|
||||
console.log('links: ' + Object.keys(links).length);
|
||||
console.log('fields: ' + Object.keys(fields).length);
|
||||
console.log('portals: ' + window.portalsCount);
|
||||
console.log('links: ' + window.linksCount);
|
||||
console.log('fields: ' + window.fieldsCount);
|
||||
}
|
||||
|
||||
window.debug.printStackTrace = function() {
|
||||
|
Reference in New Issue
Block a user