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

Issue 1238593003: Array.prototype.reverse should call [[HasProperty]] on elements before [[Get]] (Closed)

Created:
5 years, 5 months ago by Dan Ehrenberg
Modified:
5 years, 5 months ago
Reviewers:
adamk
CC:
v8-dev
Base URL:
https://chromium.googlesource.com/v8/v8.git@master
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

Array.prototype.reverse should call [[HasProperty]] on elements before [[Get]] This is a change from ES5 to ES6: When reversing an array, first it is checked whether the element exists, before the element is looked up. The order in ES6 is [[HasElement]] lower [[Get]] lower (if present) [[HasElement]] upper [[Get]] upper (if present) In ES5, on the other hand, the order was [[Get]] lower [[Get]] upper [[HasElement]] lower [[HasElement]] upper To mitigate the performance impact, this patch implements a new, third copy of reversing arrays if %_HasPackedElements. This allows us to skip all membership tests, and a quick and dirty benchmark shows that the new version is faster: Over 4 runs, the slowest for the new version: d8> var start = Date.now(); for (var i = 0; i < 100000000; i++) [1, 2, 3, 4, 5].reverse(); Date.now() - start 4658 Over 3 runs, the fastest for the old version: d8> var start = Date.now(); for (var i = 0; i < 100000000; i++) [1, 2, 3, 4, 5].reverse(); Date.now() - start 5176 BUG=v8:4223 R=adamk LOG=Y Committed: https://crrev.com/f76dfee9dfa56a0a3ca3c95d17c244cd5cc6753d Cr-Commit-Position: refs/heads/master@{#29716}

Patch Set 1 #

Patch Set 2 : Add faster PackedArrayReverse #

Patch Set 3 : Add packed implementation #

Total comments: 8

Patch Set 4 : Changes from code review #

Unified diffs Side-by-side diffs Delta from patch set Stats (+38 lines, -14 lines) Patch
M src/array.js View 1 2 3 4 chunks +25 lines, -11 lines 0 comments Download
M src/harmony-typedarray.js View 1 3 chunks +3 lines, -3 lines 0 comments Download
A test/mjsunit/es6/array-reverse-order.js View 1 1 chunk +10 lines, -0 lines 0 comments Download

Messages

Total messages: 18 (3 generated)
Dan Ehrenberg
I couldn't figure out how to trigger sparse reverse. If anyone has advice, that'd be ...
5 years, 5 months ago (2015-07-16 03:11:16 UTC) #1
adamk
High-level question: this should be visible in ES5 with getters anyway, so I don't think ...
5 years, 5 months ago (2015-07-16 19:39:20 UTC) #2
adamk
Answering my own question: https://bugs.ecmascript.org/show_bug.cgi?id=2607 Looks like neither Allen nor Brian realized that this changed ...
5 years, 5 months ago (2015-07-16 19:55:47 UTC) #3
adamk
I would tend to agree that this behavior change isn't going to break real code. ...
5 years, 5 months ago (2015-07-16 20:06:24 UTC) #4
Dan Ehrenberg
On 2015/07/16 20:06:24, adamk wrote: > I would tend to agree that this behavior change ...
5 years, 5 months ago (2015-07-16 20:43:58 UTC) #5
Dan Ehrenberg
PTAL
5 years, 5 months ago (2015-07-16 21:51:51 UTC) #6
Dan Ehrenberg
PTAL
5 years, 5 months ago (2015-07-16 21:52:09 UTC) #7
adamk
https://codereview.chromium.org/1238593003/diff/40001/src/array.js File src/array.js (left): https://codereview.chromium.org/1238593003/diff/40001/src/array.js#oldcode571 src/array.js:571: if (!IS_UNDEFINED(current_i) || low in array) { As discussed ...
5 years, 5 months ago (2015-07-16 22:08:14 UTC) #8
Toon Verwaest
https://codereview.chromium.org/1238593003/diff/40001/src/array.js File src/array.js (right): https://codereview.chromium.org/1238593003/diff/40001/src/array.js#newcode637 src/array.js:637: } else if (%_HasFastPackedElements(array)) { On 2015/07/16 22:08:13, adamk ...
5 years, 5 months ago (2015-07-16 22:15:32 UTC) #10
Dan Ehrenberg
https://codereview.chromium.org/1238593003/diff/40001/src/array.js File src/array.js (left): https://codereview.chromium.org/1238593003/diff/40001/src/array.js#oldcode571 src/array.js:571: if (!IS_UNDEFINED(current_i) || low in array) { On 2015/07/16 ...
5 years, 5 months ago (2015-07-16 22:16:49 UTC) #12
adamk
On 2015/07/16 22:15:32, Toon Verwaest wrote: > https://codereview.chromium.org/1238593003/diff/40001/src/array.js > File src/array.js (right): > > https://codereview.chromium.org/1238593003/diff/40001/src/array.js#newcode637 ...
5 years, 5 months ago (2015-07-16 22:16:50 UTC) #13
adamk
lgtm
5 years, 5 months ago (2015-07-16 22:19:09 UTC) #14
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1238593003/60001
5 years, 5 months ago (2015-07-16 22:31:33 UTC) #16
commit-bot: I haz the power
Committed patchset #4 (id:60001)
5 years, 5 months ago (2015-07-16 23:12:13 UTC) #17
commit-bot: I haz the power
5 years, 5 months ago (2015-07-16 23:12:34 UTC) #18
Message was sent while issue was closed.
Patchset 4 (id:??) landed as
https://crrev.com/f76dfee9dfa56a0a3ca3c95d17c244cd5cc6753d
Cr-Commit-Position: refs/heads/master@{#29716}

Powered by Google App Engine
This is Rietveld 408576698