RESOLVED FIXED 160836
Array.prototype.map builtin should go on the fast path when constructor===@Array
https://bugs.webkit.org/show_bug.cgi?id=160836
Summary Array.prototype.map builtin should go on the fast path when constructor===@Array
Saam Barati
Reported 2016-08-12 18:49:31 PDT
...
Attachments
Patch (7.09 KB, patch)
2016-08-14 16:47 PDT, Caio Lima
no flags
Benchmark run 03 (78.44 KB, text/plain)
2016-08-14 16:49 PDT, Caio Lima
no flags
patch I was thinking of (609 bytes, patch)
2016-08-15 11:34 PDT, Saam Barati
no flags
patch (1.87 KB, patch)
2016-08-15 15:24 PDT, Saam Barati
keith_miller: review+
patch for landing (2.76 KB, patch)
2016-08-15 15:37 PDT, Saam Barati
no flags
Caio Lima
Comment 1 2016-08-14 16:47:54 PDT
Caio Lima
Comment 2 2016-08-14 16:49:48 PDT
Created attachment 286039 [details] Benchmark run 03
Saam Barati
Comment 3 2016-08-15 11:29:48 PDT
Comment on attachment 286038 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=286038&action=review > Source/JavaScriptCore/builtins/ArrayPrototype.js:264 > + if (tempConstructor === @Array) { > + result = @Array(length); > + > + for (var i = 0; i < length; i++) { > + if (!(i in array)) > + continue; > + var mappedValue = callback.@call(thisArg, array[i], i, array); > + @putByValDirect(result, i, mappedValue); > + } > + > + return result; > + } I don't think this is quite right w.r.t the species symbol.
Saam Barati
Comment 4 2016-08-15 11:30:41 PDT
Comment on attachment 286038 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=286038&action=review > Source/JavaScriptCore/builtins/ArrayPrototype.js:281 > + if (constructor === @undefined) I think you can accomplish a speedup on ES6 bench just by making this "constructor === @Array || constructor === @undefined"
Saam Barati
Comment 5 2016-08-15 11:34:20 PDT
Created attachment 286070 [details] patch I was thinking of This is like 6-8% faster on ES6 bench. Keith, does this look correct to you
Saam Barati
Comment 6 2016-08-15 11:44:26 PDT
(In reply to comment #5) > Created attachment 286070 [details] > patch I was thinking of > > This is like 6-8% faster on ES6 bench. > Keith, does this look correct to you To elaborate, this will cause the FTL to recognize that we're doing NewArrayWithSize instead of compiling x: JSConstant(Array) y: Construct(@x, ...) For example, this program will benefit from this: ``` let x = [1,2,3]; for (let i = 0; i < 10000; i++) { x.map(f=>f); } ```
Keith Miller
Comment 7 2016-08-15 11:50:23 PDT
(In reply to comment #6) > (In reply to comment #5) > > Created attachment 286070 [details] > > patch I was thinking of > > > > This is like 6-8% faster on ES6 bench. > > Keith, does this look correct to you > > To elaborate, this will cause the FTL to recognize > that we're doing NewArrayWithSize instead > of compiling > x: JSConstant(Array) > y: Construct(@x, ...) > > For example, this program will benefit from this: > ``` > let x = [1,2,3]; > for (let i = 0; i < 10000; i++) { > x.map(f=>f); > } > ``` Yeah, I can believe that's a speedup. Although, I think we should support the Array constructor as an "intrinsic" in the DFG, it's probably a trivial change. It might also be worthwhile to make @Array a bytecode intrinsic function.
Saam Barati
Comment 8 2016-08-15 15:09:07 PDT
(In reply to comment #7) > (In reply to comment #6) > > (In reply to comment #5) > > > Created attachment 286070 [details] > > > patch I was thinking of > > > > > > This is like 6-8% faster on ES6 bench. > > > Keith, does this look correct to you > > > > To elaborate, this will cause the FTL to recognize > > that we're doing NewArrayWithSize instead > > of compiling > > x: JSConstant(Array) > > y: Construct(@x, ...) > > > > For example, this program will benefit from this: > > ``` > > let x = [1,2,3]; > > for (let i = 0; i < 10000; i++) { > > x.map(f=>f); > > } > > ``` > > Yeah, I can believe that's a speedup. Although, I think we should support > the Array constructor as an "intrinsic" in the DFG, it's probably a trivial > change. It might also be worthwhile to make @Array a bytecode intrinsic > function. I agree. I'll do this in another patch and make it a bytecode intrinsic: https://bugs.webkit.org/show_bug.cgi?id=160867
Saam Barati
Comment 9 2016-08-15 15:24:48 PDT
Keith Miller
Comment 10 2016-08-15 15:26:27 PDT
Comment on attachment 286096 [details] patch r=me.
Keith Miller
Comment 11 2016-08-15 15:27:03 PDT
I think we should we also apply this to the other Array prototype functions.
Saam Barati
Comment 12 2016-08-15 15:37:50 PDT
Created attachment 286100 [details] patch for landing
WebKit Commit Bot
Comment 13 2016-08-15 16:33:13 PDT
Comment on attachment 286100 [details] patch for landing Clearing flags on attachment: 286100 Committed r204488: <http://trac.webkit.org/changeset/204488>
WebKit Commit Bot
Comment 14 2016-08-15 16:33:19 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.