I was surprised to find that a function call returning a boolean from
a simple test was much (3x!) faster than an associative array
lookup... I was wondering if someone could explain to me how that
could be the case. Is v8 inlining the function somehow, or is the
overhead of a function call extremely low?

Note 1: I'm not complaining, I'm just curious as to how things were
working under the covers.
Note 2: The opposite is true for Firefox, which is 2x slower using the
function call than the associative array... so an optimization for one
would result in a performance regression for another... :(

Example:

------
isWhitespace:function(charCode) {
  return charCode == this.spaceCharCode || charCode ==
this.tabCharCode || ... etc ...;
},

for (var i = 0; i < aString.length; i++) {
  var isWs = this.isWhitespace(aString.charCodeAt(i));
}
------

Is 3x faster than:

------
whitespace: Associative array mapping whitespace char codes to true,

for (var i = 0; i < aString.length; i++) {
  var isWs = this.whitespace[aString.charCodeAt(i)];
}
------

Thanks in advance, Chad

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to