Reviewers: metaweta, Description: This change reduces runtime of a minimal test gadget from 2800ms to 2100ms in Chrome Beta (16.0), from 2300ms to 1800ms in Firefox Aurora (10.0), from 2300ms to 2100ms in Firefox Beta (9.0), from 1700ms to 1200ms in Safari 5.1.2
Basically, a much of the cost of es53+domado startup is freeze, and much of the cost of freeze is iterating over object properties, which includes inherited properties which have to be ignored. This change tries to use a native Object.keys function to do a fast initial filtering of the properties. Please review this at http://codereview.appspot.com/5484074/ Affected files: M src/com/google/caja/es53.js Index: src/com/google/caja/es53.js =================================================================== --- src/com/google/caja/es53.js (revision 4681) +++ src/com/google/caja/es53.js (working copy) @@ -221,6 +221,17 @@ }; } + var hasOwnProperty = Object.prototype.hasOwnProperty; + var fastOwnKeys = Object.keys || function fastOwnKeys(o) { + // Due to IE<9 bugs, this isn't identical to Object.keys, but we're + // only using this to find ___ properties, and for that it works fine. + var keys = []; + for (var k in o) { + if (hasOwnProperty.call(o, k)) { keys.push(k); } + } + return keys; + }; + Object.prototype.freeze___ = function() { // Frozen means all the properties are neither writable nor // configurable, and the object itself is not extensible. @@ -233,9 +244,9 @@ if (this.v___ === deferredV) { this.v___('length'); } - for (var i in this) { - if (!this.hasOwnProperty(i)) { continue; } - if (isNumericName(i)) { continue; } + var keys = fastOwnKeys(this); + for (var k = 0, n = keys.length; k < n; k++) { + var i = keys[k]; var m = i.match(endsWith_v___); if (!m) { continue; } var P = m[1];
