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

Issue 1549016: [Not for commit] Make Array.splice change receiver's FixedArray when significant part is cut. (Closed)

Created:
10 years, 8 months ago by iegorov
Modified:
9 years, 7 months ago
Reviewers:
antonm
CC:
Erik Corry
Visibility:
Public.

Description

[Not for commit] Make Array.splice change receiver's FixedArray when significant part is cut. When Array.splice removes significant part of original array, it could be a good idea to allocate memory for the part left in receiver and not the one removed from it.

Patch Set 1 #

Total comments: 13

Patch Set 2 : fixed some stupid mistakes #

Total comments: 2

Patch Set 3 : Make CL pass all tests, reorganize code a bit. #

Patch Set 4 : Additional tests for splice #

Total comments: 5
Unified diffs Side-by-side diffs Delta from patch set Stats (+148 lines, -72 lines) Patch
M src/builtins.cc View 1 2 2 chunks +114 lines, -72 lines 5 comments Download
M test/mjsunit/array-splice.js View 1 chunk +34 lines, -0 lines 0 comments Download

Messages

Total messages: 7 (0 generated)
iegorov
Anton, Could you please have a look? Thank you in advance. http://codereview.chromium.org/1549016/diff/1/2 File src/builtins.cc (right): ...
10 years, 8 months ago (2010-04-02 16:17:24 UTC) #1
antonm
+ Erik as that was originally his idea. First pass comments. http://codereview.chromium.org/1549016/diff/1/2 File src/builtins.cc (right): ...
10 years, 8 months ago (2010-04-02 16:39:29 UTC) #2
iegorov
Anton, Thank you for comments. When have some time, please take a look at new ...
10 years, 8 months ago (2010-04-02 18:29:06 UTC) #3
antonm
mostly lgtm, but I very agree with Erik that before submitting it, we need some ...
10 years, 8 months ago (2010-04-02 18:41:18 UTC) #4
antonm
http://codereview.chromium.org/1549016/diff/12001/8002 File src/builtins.cc (right): http://codereview.chromium.org/1549016/diff/12001/8002#newcode728 src/builtins.cc:728: (2 * actual_delete_count >= len + item_count)) { looks ...
10 years, 8 months ago (2010-04-05 12:21:13 UTC) #5
iegorov
Anton, Thank you once again for comments. First of all, I have doubts about boundary, ...
10 years, 8 months ago (2010-04-05 13:01:48 UTC) #6
antonm
10 years, 8 months ago (2010-04-05 14:34:29 UTC) #7
Regarding if we should commit it at all.  I don't know :)  The code seems to be
notably more complicated (and ArrayShift is not the simplest piece of code
already).  It's obvious we could make a benchmark which shows the benefit of new
approach, but as there is no 'real' benchmark, I'd suggest to attempt to gather
real world stats.

For example, you could write a patch that will gather starts about all the
array.splice operations in, say, GMail, Wave and see if those apps would benefit
from this patch.

More radical approach would be to embed this stat gathering into Chrome itself
to see if it's common operations on some other sites.

http://codereview.chromium.org/1549016/diff/12001/8002
File src/builtins.cc (right):

http://codereview.chromium.org/1549016/diff/12001/8002#newcode728
src/builtins.cc:728: (2 * actual_delete_count >= len + item_count)) {
Sorry, I should have been explicit but I didn't account for item_writes as there
is no way to escape them (unless we'd like to allocate result's elements in the
stack, kidding :).

So estimate for new approach for result allocation appears to be the same for
you and me: actual_start + 2*tail_length + item_count.

Now to estimates for the present approach.  My mistake was I only thought about
one case when length of fixed element array is enough.  Now to your more
detailed analysis.

item_count == actual_delete_count:

It's not just item_count---it's 2*item_count if you account for new elements
writes---item_count to copy old items + item_count to write new ones.  So we do
less writes with new approach given actual_start + 2*tail_length < item_count.

item_count < actual_delete_count:

I think we need item_count (new elements writes) + tail_length (to move former
elements) + (actual_delete_count - item_count) (to fill with the holes) (if we
cannot apply new space trick which could save additional moves)

item_count > actual_delete_count:

even more complicated as we need to fill with the holes the rest of newly
allocated array.

Overall numbers seems quite different and I suspect (but I didn't think
properly) when simple heuristics could lead to worse behaviour.

So could you experiment (if you please, of course) if it's possible to refactor
the code in the following fashion:

for all three cases (item_count <>= actual_delete_count) we decide how exactly
we should go?

On 2010/04/05 13:01:49, iegorov wrote:
> My counts differ:
> - when making inplace (terminology: that's what I do, right?): we need
> actual_start + items_count + tail_length to create result, and tail_length
> writes to make holes in receiver;
> - unfortunately when doing out of place, the result differs on items_count
> compared to actual_delete_count. When equal: it is only items_count, when
> items_count is less than actual_delete_count it is items_count + tail_length
> moves, otherwise it results in creation of a new array, which is items_count +
> tail_length + actual_start.
> 
> The question is what is the boundary? Should I count it precisely? 
> On 2010/04/05 12:21:13, antonm wrote:
> > looks like you're trying to keep the number of writes minimal.  In this case
> for
> > inplace result number of writes is actual_start + tail_length (+ tail_length
> to
> > fill with the holes) while out of place result requires item_count +
> tail_length
> > moves.
> > 
> > Thus condition might be actual_start + tail_length >= item_count. 
> 
>

Powered by Google App Engine
This is Rietveld 408576698