Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Issue 1348943002: Slightly optimize performance of ToLength() (Closed)

Created:
5 years, 3 months ago by aperez
Modified:
5 years, 3 months ago
CC:
v8-reviews_googlegroups.com
Base URL:
https://chromium.googlesource.com/v8/v8.git@master
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

Slightly 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 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+8 lines, -4 lines) Patch
M src/macros.py View 1 chunk +3 lines, -0 lines 0 comments Download
M src/runtime.js View 1 chunk +4 lines, -3 lines 0 comments Download
M src/v8natives.js View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 10 (2 generated)
aperez
5 years, 3 months ago (2015-09-16 21:22:24 UTC) #2
adamk
I'm not sure 1.15x speedup is worth doing a one-off like this. The bigger win ...
5 years, 3 months ago (2015-09-16 22:02:55 UTC) #4
Benedikt Meurer
I agree with adam, that the benefit of this seems rather small. How about implementing ...
5 years, 3 months ago (2015-09-17 03:51:04 UTC) #5
aperez
On 2015/09/17 03:51:04, Benedikt Meurer wrote: > I agree with adam, that the benefit of ...
5 years, 3 months ago (2015-09-17 15:34:10 UTC) #6
adamk
On 2015/09/17 15:34:10, aperez wrote: > On 2015/09/17 03:51:04, Benedikt Meurer wrote: > > I ...
5 years, 3 months ago (2015-09-17 17:50:49 UTC) #7
Benedikt Meurer
On 2015/09/17 17:50:49, adamk wrote: > On 2015/09/17 15:34:10, aperez wrote: > > On 2015/09/17 ...
5 years, 3 months ago (2015-09-17 18:21:53 UTC) #8
aperez
On 2015/09/17 18:21:53, Benedikt Meurer wrote: > On 2015/09/17 17:50:49, adamk wrote: > > On ...
5 years, 3 months ago (2015-09-17 19:17:07 UTC) #9
aperez
5 years, 3 months ago (2015-09-17 20:13:28 UTC) #10
Message was sent while issue was closed.
On 2015/09/17 19:17:07, aperez wrote:
> On 2015/09/17 18:21:53, Benedikt Meurer wrote:
> > On 2015/09/17 17:50:49, adamk wrote:
> > > On 2015/09/17 15:34:10, aperez wrote:
> > > > On 2015/09/17 03:51:04, Benedikt Meurer wrote:
> > > > > I agree with adam, that the benefit of this seems rather small. How
> about
> > > > > implementing a %_ToLength intrinsic, based on the ToNumberStub?
> > > > 
> > > > Ack, I'll try to go down that route.
> > > > 
> > > > For reference, the speedup of only doing the kMaxSafeInteger change is
> > 1.04x,
> > > I
> > > > have posted some numbers in this comment:
> > > > 
> > > >   https://code.google.com/p/v8/issues/detail?id=3087#c30
> > > > 
> > > > I guess it's not much worth it to have a CL only with the
kMaxSafeInteger
> > bit.
> > > > WDYT?
> > > 
> > > I'm really fine either way; I'd be happy to stamp a change that did just
the
> > > kMaxSafeInteger bit to make it clear from reading the code that it's a
> > constant.
> > 
> > Me too.
> 
> I'll submit the kMaxSafeInteger bit as a separate review, then.
> Thanks for the input!

FWIW, I have closed this issue. A separate CL with the kMaxSafeInteger thingy
only is now at: https://codereview.chromium.org/1353953002/

Powered by Google App Engine
This is Rietveld 408576698