Export to GitHub

v8cgi - issue #95

JavaScript code and performance improvements


Posted on Jun 16, 2011 by Happy Bird

1.Where it was safe == operators have been replaced with === to avoid unnecessary type casting. 2.length attribute of arrays assign to variable to speed up the for-loop execution 3. hasOwnProperty verification for all for-in loops added - to avoid unnecessary walk-through prototype elements 4. missing semicolons added 5. double variable declarations removed from some functions

Attachments

Comment #1

Posted on Jun 17, 2011 by Happy Giraffe

Those hasOwnProperty checks seem to be unnecessary: all those objects are simple JS data structures with proto === Object.prototype, e.g. no non-own properties are being enumerated... ?

Comment #2

Posted on Jun 20, 2011 by Happy Bird

Some of JS developers would say that hasOwnProperty check should be an integral part of for..in loop. Even if there is nothing added to object's prototype. However it is just theoretical discussion. In practice - I never had a need to navigate through prototype properties of an object, this is why I always add the check. In such case I never have to bother when I add something enumerable to the prototype...

Comment #3

Posted on Jun 22, 2011 by Happy Giraffe

I can guarantee that I never modify Object.prototype, which is why adding hasOwnProperty check to "for (var p in {})" is redundant...

Also, consistently, I never enumerate non-Objects with "for (var p in what)" - which is why I can freely extend their prototypes :)

Comment #4

Posted on Jul 27, 2011 by Happy Giraffe

Revision 918 applies those parts of this patch which optimize array length getters in loops.

Comment #5

Posted on Sep 3, 2011 by Happy Bird

Thanks, the array lengths were the most important.

Status: Fixed

Labels:
Type-Patch