Bug 222539 - [JSC] Optimize getEnumerableLength
Summary: [JSC] Optimize getEnumerableLength
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: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-03-01 03:01 PST by Yusuke Suzuki
Modified: 2021-03-02 15:34 PST (History)
8 users (show)

See Also:


Attachments
Patch (9.64 KB, patch)
2021-03-01 03:07 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (12.28 KB, patch)
2021-03-01 03:46 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (12.38 KB, patch)
2021-03-01 03:48 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (12.38 KB, patch)
2021-03-01 03:50 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (13.90 KB, patch)
2021-03-01 03:57 PST, Yusuke Suzuki
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (13.19 KB, patch)
2021-03-01 04:07 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (12.15 KB, patch)
2021-03-02 13:43 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (12.05 KB, patch)
2021-03-02 13:49 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2021-03-01 03:01:46 PST
[JSC] Rename getEnumerableLength to getEnumerableLengthTracingJSProxy, and remove indirect call of getEnumerableLength
Comment 1 Yusuke Suzuki 2021-03-01 03:07:34 PST
Created attachment 421802 [details]
Patch
Comment 2 Yusuke Suzuki 2021-03-01 03:46:11 PST
Created attachment 421803 [details]
Patch
Comment 3 Yusuke Suzuki 2021-03-01 03:48:22 PST
Created attachment 421804 [details]
Patch
Comment 4 Yusuke Suzuki 2021-03-01 03:50:22 PST
Created attachment 421805 [details]
Patch
Comment 5 Yusuke Suzuki 2021-03-01 03:57:59 PST
Created attachment 421806 [details]
Patch
Comment 6 Yusuke Suzuki 2021-03-01 04:07:05 PST
Created attachment 421807 [details]
Patch
Comment 7 Alexey Shvayka 2021-03-01 08:14:54 PST
Comment on attachment 421807 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:8
> +        Now getEnumerableLength is only overridden by JSProxy. And this is called in the critical path of propertyNameEnumerator.

1. I am pretty sure we can remove JSProxy handling from getEnumerableLength() because it won't hit fast path of for/in anyway: canAccessPropertiesQuicklyForEnumeration() will reject it due to overriden getOwnPropertyNames().
2. We can't optimize access to JSProxy's indices as they are handled in JSDOMWindow::getOwnPropertySlotByIndex().
3. For/in over window is super slow anyway, as it yield a lot of event handler properties etc, and doesn't seem like a case we should optimize for.
4. I believe we can optimize enumeration for StringObject / Arguments / TypedArray via getEnumerableLength() overrides, but can we (relatively easily) speed up indexed access for them?
Comment 8 Yusuke Suzuki 2021-03-02 13:40:21 PST
Comment on attachment 421807 [details]
Patch

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

>> Source/JavaScriptCore/ChangeLog:8
>> +        Now getEnumerableLength is only overridden by JSProxy. And this is called in the critical path of propertyNameEnumerator.
> 
> 1. I am pretty sure we can remove JSProxy handling from getEnumerableLength() because it won't hit fast path of for/in anyway: canAccessPropertiesQuicklyForEnumeration() will reject it due to overriden getOwnPropertyNames().
> 2. We can't optimize access to JSProxy's indices as they are handled in JSDOMWindow::getOwnPropertySlotByIndex().
> 3. For/in over window is super slow anyway, as it yield a lot of event handler properties etc, and doesn't seem like a case we should optimize for.
> 4. I believe we can optimize enumeration for StringObject / Arguments / TypedArray via getEnumerableLength() overrides, but can we (relatively easily) speed up indexed access for them?

Thanks,

1, 2, 3: Sounds good. I'll remove JSProxy chasing part.
4. I think they are rare enough, so we could support with TypeInfo flag in the future. For now, my plan is just keeping it as is (not optimized yet).
Comment 9 Yusuke Suzuki 2021-03-02 13:41:50 PST
Comment on attachment 421807 [details]
Patch

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

>>> Source/JavaScriptCore/ChangeLog:8
>>> +        Now getEnumerableLength is only overridden by JSProxy. And this is called in the critical path of propertyNameEnumerator.
>> 
>> 1. I am pretty sure we can remove JSProxy handling from getEnumerableLength() because it won't hit fast path of for/in anyway: canAccessPropertiesQuicklyForEnumeration() will reject it due to overriden getOwnPropertyNames().
>> 2. We can't optimize access to JSProxy's indices as they are handled in JSDOMWindow::getOwnPropertySlotByIndex().
>> 3. For/in over window is super slow anyway, as it yield a lot of event handler properties etc, and doesn't seem like a case we should optimize for.
>> 4. I believe we can optimize enumeration for StringObject / Arguments / TypedArray via getEnumerableLength() overrides, but can we (relatively easily) speed up indexed access for them?
> 
> Thanks,
> 
> 1, 2, 3: Sounds good. I'll remove JSProxy chasing part.
> 4. I think they are rare enough, so we could support with TypeInfo flag in the future. For now, my plan is just keeping it as is (not optimized yet).

For typed-array case, we could just extend the support by using canGetIndexQuickly like feature.
Comment 10 Yusuke Suzuki 2021-03-02 13:43:39 PST
Created attachment 421988 [details]
Patch
Comment 11 Yusuke Suzuki 2021-03-02 13:49:31 PST
Created attachment 421992 [details]
Patch
Comment 12 Alexey Shvayka 2021-03-02 13:55:24 PST
(In reply to Yusuke Suzuki from comment #9)
> For typed-array case, we could just extend the support by using canGetIndexQuickly like feature.

Yeah, we don't need getEnumerableLength() in a method table for that.
Regarding other objects: we can't optimize indexed access for them via IndexedForInContext, only enumeration, which won't benefit much + they are rare.

Fast for/in for TypedArray can be tracked in https://bugs.webkit.org/show_bug.cgi?id=135033.
Comment 13 EWS 2021-03-02 15:33:48 PST
Committed r273766: <https://commits.webkit.org/r273766>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 421992 [details].
Comment 14 Radar WebKit Bug Importer 2021-03-02 15:34:19 PST
<rdar://problem/74952502>