Bug 176654 - [JSC] Optimize Object.keys by using careful array allocation
Summary: [JSC] Optimize Object.keys by using careful array allocation
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: 2017-09-09 09:17 PDT by Yusuke Suzuki
Modified: 2017-09-27 12:32 PDT (History)
8 users (show)

See Also:


Attachments
Patch (12.39 KB, patch)
2017-09-09 09:23 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (13.80 KB, patch)
2017-09-09 09:39 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (13.90 KB, patch)
2017-09-09 09:40 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (10.58 KB, patch)
2017-09-09 10:09 PDT, Yusuke Suzuki
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2017-09-09 09:17:36 PDT
[JSC] Optimize Object.keys by using careful array allocation
Comment 1 Yusuke Suzuki 2017-09-09 09:23:43 PDT
Created attachment 320344 [details]
Patch
Comment 2 Yusuke Suzuki 2017-09-09 09:31:25 PDT
Comment on attachment 320344 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:13
> +        but it rarely appears.

Then, ProxyObject case goes to the generic path.
Comment 3 Yusuke Suzuki 2017-09-09 09:39:36 PDT
Created attachment 320345 [details]
Patch
Comment 4 Yusuke Suzuki 2017-09-09 09:40:46 PDT
Created attachment 320346 [details]
Patch
Comment 5 Yusuke Suzuki 2017-09-09 10:09:12 PDT
Created attachment 320347 [details]
Patch
Comment 6 Darin Adler 2017-09-10 14:58:54 PDT
Comment on attachment 320347 [details]
Patch

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

> Source/JavaScriptCore/runtime/ObjectConstructor.h:125
> -JSArray* ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode);
> +JSValue ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode);

Why this change? Nothing in the change log explains it. The function still seems to always return a JSArray*. Is it a performance optimization to move the conversion from JSArray* to JSValue inside the function?

If the change isn’t needed, then it seems useful to follow the general C++ coding style rule of not widening types unnecessarily in case the narrower type can be of use for performance optimization or otherwise useful in the future.
Comment 7 Yusuke Suzuki 2017-09-11 01:04:55 PDT
Comment on attachment 320347 [details]
Patch

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

>> Source/JavaScriptCore/runtime/ObjectConstructor.h:125
>> +JSValue ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode);
> 
> Why this change? Nothing in the change log explains it. The function still seems to always return a JSArray*. Is it a performance optimization to move the conversion from JSArray* to JSValue inside the function?
> 
> If the change isn’t needed, then it seems useful to follow the general C++ coding style rule of not widening types unnecessarily in case the narrower type can be of use for performance optimization or otherwise useful in the future.

I thought it is not so good that JSValue::encode(nullptr as JSCell*) happens if the error occurrs. But either is ok to me.
Comment 8 Yusuke Suzuki 2017-09-11 01:10:17 PDT
Committed r221853: <http://trac.webkit.org/changeset/221853>
Comment 10 Saam Barati 2017-09-11 11:56:14 PDT
Comment on attachment 320347 [details]
Patch

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

> Source/JavaScriptCore/runtime/ObjectConstructor.cpp:402
> +        values->putDirectIndex(exec, index++, value);

Isn't this an observable change in JS semantics?
Comment 11 Darin Adler 2017-09-11 19:07:15 PDT
Comment on attachment 320347 [details]
Patch

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

>>> Source/JavaScriptCore/runtime/ObjectConstructor.h:125
>>> +JSValue ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode);
>> 
>> Why this change? Nothing in the change log explains it. The function still seems to always return a JSArray*. Is it a performance optimization to move the conversion from JSArray* to JSValue inside the function?
>> 
>> If the change isn’t needed, then it seems useful to follow the general C++ coding style rule of not widening types unnecessarily in case the narrower type can be of use for performance optimization or otherwise useful in the future.
> 
> I thought it is not so good that JSValue::encode(nullptr as JSCell*) happens if the error occurrs. But either is ok to me.

Not different from returning "JSValue { }"; the JSValue(JSCell*) constructor handles nullptr in exactly that way. If we wanted to optimize by avoiding the branch, I don’t think returning JSValue accomplishes that.
Comment 12 Yusuke Suzuki 2017-09-12 09:53:47 PDT
Comment on attachment 320347 [details]
Patch

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

>> Source/JavaScriptCore/runtime/ObjectConstructor.cpp:402
>> +        values->putDirectIndex(exec, index++, value);
> 
> Isn't this an observable change in JS semantics?

I changed these code to align them to the spec (previously, our implementation does not follow the spec.)
I'll add the test for this.
Comment 13 Saam Barati 2017-09-12 11:41:02 PDT
(In reply to Yusuke Suzuki from comment #12)
> Comment on attachment 320347 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=320347&action=review
> 
> >> Source/JavaScriptCore/runtime/ObjectConstructor.cpp:402
> >> +        values->putDirectIndex(exec, index++, value);
> > 
> > Isn't this an observable change in JS semantics?
> 
> I changed these code to align them to the spec (previously, our
> implementation does not follow the spec.)
> I'll add the test for this.

👍🏽
Comment 14 Radar WebKit Bug Importer 2017-09-27 12:32:28 PDT
<rdar://problem/34693450>