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

Issue 1513020: Early specialize sorting functions depending if there is a custom comparator or not. (Closed)

Created:
10 years, 8 months ago by antonm
Modified:
9 years, 4 months ago
CC:
v8-dev
Visibility:
Public.

Description

Early specialize sorting functions depending if there is a custom comparator or not. Committed: http://code.google.com/p/v8/source/detail?r=4356

Patch Set 1 #

Total comments: 4

Patch Set 2 : Addressing Ivan's comments #

Total comments: 8
Unified diffs Side-by-side diffs Delta from patch set Stats (+74 lines, -13 lines) Patch
M src/array.js View 1 6 chunks +74 lines, -13 lines 8 comments Download

Messages

Total messages: 6 (0 generated)
antonm
Mads, Ivan, may you have a look? It's not a huge boost, but hopefully it ...
10 years, 8 months ago (2010-04-07 12:10:42 UTC) #1
iegorov
LGTM http://codereview.chromium.org/1513020/diff/1/2 File src/array.js (right): http://codereview.chromium.org/1513020/diff/1/2#newcode657 src/array.js:657: var order = (a[mid] === element) ? 0 ...
10 years, 8 months ago (2010-04-07 12:27:57 UTC) #2
Mads Ager (chromium)
LGTM I do find the duplication annoying though, so let's not make it a habit. ...
10 years, 8 months ago (2010-04-07 12:41:57 UTC) #3
antonm
Thanks a lot, guys. @Mads: wholeheartedly agree. http://codereview.chromium.org/1513020/diff/1/2 File src/array.js (right): http://codereview.chromium.org/1513020/diff/1/2#newcode657 src/array.js:657: var order ...
10 years, 8 months ago (2010-04-07 13:10:12 UTC) #4
Lasse Reichstein
Well, LGTM, but I never liked the current solution anyway :) http://codereview.chromium.org/1513020/diff/7001/8001 File src/array.js (right): ...
10 years, 8 months ago (2010-04-07 17:43:27 UTC) #5
antonm
10 years, 8 months ago (2010-04-07 17:47:27 UTC) #6
Thanks, Lasse.  I'll prepare a CL cleaning up all the stuff you mentioned and
run it through perfbots.

http://codereview.chromium.org/1513020/diff/7001/8001
File src/array.js (right):

http://codereview.chromium.org/1513020/diff/7001/8001#newcode649
src/array.js:649: var element = a[i];
On 2010/04/07 17:43:27, Lasse Reichstein wrote:
> Come to think of it, using binary search seems overkill, since we are going to
> read and write every element after the found position anyway when we place the
> element. 
> Just do a backwards search-and-copy until finding the correct location. I.e,
> something like:
> 
>   for (var j = i - 1; j >= from; j--) {
>     var tmp = a[j];
>     var order = tmp === element ? 0 : comparefn.call(null,tmp,element);
>     if (order > 0) {
>       a[j + 1] = tmp;
>     } else if (order == 0) {
>       j--;
>       break;
>     }
>   }
>   a[j + 1] = element;
> 

Agree.  That's the thing I implemented in C++, but calling JS from C++ is
expensive.  I'll give it a try, but for now it doesn't look like the main reason
for slowness.

http://codereview.chromium.org/1513020/diff/7001/8001#newcode658
src/array.js:658: 0 : comparefn.call(null, a[mid], element);
On 2010/04/07 17:43:27, Lasse Reichstein wrote:
> Reading a[mid] twice. Maybe assign to temporary variable.
> 

Thanks, will give it a try.

http://codereview.chromium.org/1513020/diff/7001/8001#newcode660
src/array.js:660: min = max = mid;
On 2010/04/07 17:43:27, Lasse Reichstein wrote:
> No need to assign to max.

Will give it a try as well.

http://codereview.chromium.org/1513020/diff/7001/8001#newcode716
src/array.js:716: // If it isn't, we are allowed arbitrary behavior by ECMA
15.4.4.11.
On 2010/04/07 17:43:27, Lasse Reichstein wrote:
> Comment doesn't make sense any more (not here, at least).

Agree.  Will remove.

Powered by Google App Engine
This is Rietveld 408576698