DescriptionSlightly optimize performance of ToLength()
This patch does two small optimizations to the implementation of ToLength():
- The call to ToInteger() is manually inlined into ToLength().
- Uses a kMaxSafeInteger macro (which expands to 2^53-1) instead of accessing
Number.MAX_SAFE_INTEGER. This saves loading the attribute from the Number
object.
Those changes provide a 1.15x speedup when invoking an Array method which ends
up calling ToLength(). Note that for pure array objects V8 provides a C++ fast
path, and the code path that uses ToLength() is triggered e.g. for array-like
objects which have a getter for "length". The following code was used to
measure the speedup:
var data = {};
Object.defineProperty(data, "length", {
get: function () {
return 0;
},
});
var NCALLS = 5000000;
var timing = performance.now();
for (var n = 0; n < NCALLS; n++) Array.prototype.indexOf.call(data, 0);
timing = performance.now() - timing;
print(timing / NCALLS * 1000 * 1000, "ns/call");
BUG=v8:3087
LOG=N
Patch Set 1 #
Messages
Total messages: 10 (2 generated)
|