Bug 217928 - %TypedArray%#sort helper functions should be globalPrivate
Summary: %TypedArray%#sort helper functions should be globalPrivate
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ross Kirsling
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-10-19 16:25 PDT by Ross Kirsling
Modified: 2020-10-19 23:41 PDT (History)
10 users (show)

See Also:


Attachments
Patch (6.22 KB, patch)
2020-10-19 16:28 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch for landing (6.21 KB, patch)
2020-10-19 16:36 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch for landing (9.97 KB, patch)
2020-10-19 18:04 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch for landing (9.97 KB, patch)
2020-10-19 20:35 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ross Kirsling 2020-10-19 16:25:14 PDT
%TypedArray%#sort helper functions should be globalPrivate
Comment 1 Ross Kirsling 2020-10-19 16:28:26 PDT
Created attachment 411810 [details]
Patch
Comment 2 Yusuke Suzuki 2020-10-19 16:30:59 PDT
Comment on attachment 411810 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=411810&action=review

r=me

> Source/JavaScriptCore/builtins/TypedArrayPrototype.js:212
> +    var buffer = [];
> +    buffer.length = valueCount;

Use `var buffer = @newArrayWithSize(valueCount)`.
Comment 3 Ross Kirsling 2020-10-19 16:36:23 PDT
Created attachment 411812 [details]
Patch for landing
Comment 4 Alexey Shvayka 2020-10-19 16:38:49 PDT
Comment on attachment 411810 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=411810&action=review

> Source/JavaScriptCore/builtins/GlobalOperations.js:132
> +function sortMin(a, b)

In future, we may consider replacing this (and maxWithPositives() of ArrayPrototype.js) with exposed Math.{min,max} built-ins as they have fast path for 2 arguments.

> Source/JavaScriptCore/builtins/TypedArrayPrototype.js:227
> +        for(var i = 0; i < valueCount; i++)

nit: space before a parentheses and using pre-increment instead of post-increment (based on https://bugs.webkit.org/show_bug.cgi?id=202582#c12).
Comment 5 Ross Kirsling 2020-10-19 18:04:39 PDT
Created attachment 411821 [details]
Patch for landing
Comment 6 Ross Kirsling 2020-10-19 18:11:21 PDT
Thanks for the double review!
Comment 7 Alexey Shvayka 2020-10-19 18:35:20 PDT
Comment on attachment 411821 [details]
Patch for landing

View in context: https://bugs.webkit.org/attachment.cgi?id=411821&action=review

> Source/JavaScriptCore/runtime/JSGlobalObject.cpp:1231
> +            init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mathProtoFuncMin, TruncIntrinsic));

If there isn't a "race condition" during built-in objects init, we can reuse this JSFunction in MathObject::finishCreation() via `globalObject->linkTimeConstant(LinkTimeConstant::min);` to avoid creating the second one?
Comment 8 Ross Kirsling 2020-10-19 19:21:34 PDT
(In reply to Alexey Shvayka from comment #7)
> Comment on attachment 411821 [details]
> Patch for landing
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=411821&action=review
> 
> > Source/JavaScriptCore/runtime/JSGlobalObject.cpp:1231
> > +            init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mathProtoFuncMin, TruncIntrinsic));
> 
> If there isn't a "race condition" during built-in objects init, we can reuse
> this JSFunction in MathObject::finishCreation() via
> `globalObject->linkTimeConstant(LinkTimeConstant::min);` to avoid creating
> the second one?

Is there a precedent for that? I was just mimicking mathProtoFuncTrunc here.
Comment 9 Alexey Shvayka 2020-10-19 19:48:25 PDT
Comment on attachment 411821 [details]
Patch for landing

View in context: https://bugs.webkit.org/attachment.cgi?id=411821&action=review

>>> Source/JavaScriptCore/runtime/JSGlobalObject.cpp:1231
>>> +            init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mathProtoFuncMin, TruncIntrinsic));
>> 
>> If there isn't a "race condition" during built-in objects init, we can reuse this JSFunction in MathObject::finishCreation() via `globalObject->linkTimeConstant(LinkTimeConstant::min);` to avoid creating the second one?
> 
> Is there a precedent for that? I was just mimicking mathProtoFuncTrunc here.

Not that I can find; it might be better to do this optimization in a separate patch, for all link-time-constants possible.
Oh, and please set the correct intrinsic (TruncIntrinsic => MinIntrinsic), as it's what DFG uses to emit the fast path.
Comment 10 Ross Kirsling 2020-10-19 20:34:11 PDT
(In reply to Alexey Shvayka from comment #9)
> Oh, and please set the correct intrinsic (TruncIntrinsic => MinIntrinsic),
> as it's what DFG uses to emit the fast path.

Oh geez, what a silly mistake. Thanks.
Comment 11 Ross Kirsling 2020-10-19 20:35:14 PDT
Created attachment 411834 [details]
Patch for landing
Comment 12 EWS 2020-10-19 23:40:48 PDT
Committed r268715: <https://trac.webkit.org/changeset/268715>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 411834 [details].
Comment 13 Radar WebKit Bug Importer 2020-10-19 23:41:19 PDT
<rdar://problem/70472747>