Bug 161708 - Make HasOwnProperty faster
Summary: Make HasOwnProperty faster
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Saam Barati
URL:
Keywords:
Depends on: 161775
Blocks:
  Show dependency treegraph
 
Reported: 2016-09-07 13:19 PDT by Saam Barati
Modified: 2016-09-20 08:59 PDT (History)
18 users (show)

See Also:


Attachments
WIP (36.55 KB, patch)
2016-09-15 13:56 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
WIP (42.89 KB, patch)
2016-09-16 01:26 PDT, Saam Barati
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews103 for mac-yosemite (1.81 MB, application/zip)
2016-09-16 03:17 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews106 for mac-yosemite-wk2 (1.31 MB, application/zip)
2016-09-16 03:21 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews115 for mac-yosemite (1.73 MB, application/zip)
2016-09-16 03:26 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews122 for ios-simulator-elcapitan-wk2 (1019.41 KB, application/zip)
2016-09-16 05:34 PDT, Build Bot
no flags Details
patch (59.21 KB, patch)
2016-09-18 01:27 PDT, Saam Barati
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews102 for mac-yosemite (1.83 MB, application/zip)
2016-09-18 02:27 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews107 for mac-yosemite-wk2 (1.45 MB, application/zip)
2016-09-18 02:32 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews112 for mac-yosemite (2.19 MB, application/zip)
2016-09-18 02:35 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews123 for ios-simulator-elcapitan-wk2 (6.11 MB, application/zip)
2016-09-18 02:41 PDT, Build Bot
no flags Details
patch (59.22 KB, patch)
2016-09-18 10:54 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (59.21 KB, patch)
2016-09-18 10:56 PDT, Saam Barati
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-yosemite (867.28 KB, application/zip)
2016-09-18 12:04 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews106 for mac-yosemite-wk2 (1.03 MB, application/zip)
2016-09-18 12:08 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews117 for mac-yosemite (1.55 MB, application/zip)
2016-09-18 12:11 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews124 for ios-simulator-elcapitan-wk2 (7.51 MB, application/zip)
2016-09-18 12:17 PDT, Build Bot
no flags Details
patch (59.75 KB, patch)
2016-09-19 15:12 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (59.75 KB, patch)
2016-09-19 16:19 PDT, Saam Barati
ggaren: review+
Details | Formatted Diff | Diff
patch for landing (60.99 KB, patch)
2016-09-19 17:43 PDT, Saam Barati
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Saam Barati 2016-09-07 13:19:39 PDT
Speedometer spend around 2-2.5% of its time in HasOwnProperty. Lets try to make this faster to speed up speedometer.
Comment 1 Saam Barati 2016-09-15 13:56:55 PDT
Created attachment 288996 [details]
WIP

Looks to be a 1-2% speedometer progression.
Comment 2 Saam Barati 2016-09-16 01:26:31 PDT
Created attachment 289050 [details]
WIP

works with symbols now too. I need to implement 32-bit now.
Comment 3 Build Bot 2016-09-16 03:17:35 PDT
Comment on attachment 289050 [details]
WIP

Attachment 289050 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/2086449

Number of test failures exceeded the failure limit.
Comment 4 Build Bot 2016-09-16 03:17:38 PDT
Created attachment 289052 [details]
Archive of layout-test-results from ews103 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews103  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 5 Build Bot 2016-09-16 03:21:42 PDT
Comment on attachment 289050 [details]
WIP

Attachment 289050 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/2086453

Number of test failures exceeded the failure limit.
Comment 6 Build Bot 2016-09-16 03:21:45 PDT
Created attachment 289053 [details]
Archive of layout-test-results from ews106 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 7 Build Bot 2016-09-16 03:26:11 PDT
Comment on attachment 289050 [details]
WIP

Attachment 289050 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/2086454

Number of test failures exceeded the failure limit.
Comment 8 Build Bot 2016-09-16 03:26:16 PDT
Created attachment 289054 [details]
Archive of layout-test-results from ews115 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews115  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 9 Build Bot 2016-09-16 05:34:04 PDT
Comment on attachment 289050 [details]
WIP

Attachment 289050 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/2087121

Number of test failures exceeded the failure limit.
Comment 10 Build Bot 2016-09-16 05:34:08 PDT
Created attachment 289056 [details]
Archive of layout-test-results from ews122 for ios-simulator-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews122  Port: ios-simulator-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 11 Saam Barati 2016-09-18 01:27:55 PDT
Created attachment 289196 [details]
patch
Comment 12 WebKit Commit Bot 2016-09-18 01:30:21 PDT
Attachment 289196 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:77:  One line control clauses should not use braces.  [whitespace/braces] [4]
ERROR: Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:104:  Missing space before {  [whitespace/braces] [5]
Total errors found: 2 in 34 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Build Bot 2016-09-18 02:27:51 PDT
Comment on attachment 289196 [details]
patch

Attachment 289196 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/2098907

Number of test failures exceeded the failure limit.
Comment 14 Build Bot 2016-09-18 02:27:55 PDT
Created attachment 289197 [details]
Archive of layout-test-results from ews102 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews102  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 15 Build Bot 2016-09-18 02:32:41 PDT
Comment on attachment 289196 [details]
patch

Attachment 289196 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/2098911

Number of test failures exceeded the failure limit.
Comment 16 Build Bot 2016-09-18 02:32:44 PDT
Created attachment 289198 [details]
Archive of layout-test-results from ews107 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 17 Build Bot 2016-09-18 02:35:38 PDT
Comment on attachment 289196 [details]
patch

Attachment 289196 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/2098910

Number of test failures exceeded the failure limit.
Comment 18 Build Bot 2016-09-18 02:35:42 PDT
Created attachment 289199 [details]
Archive of layout-test-results from ews112 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews112  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 19 Build Bot 2016-09-18 02:41:28 PDT
Comment on attachment 289196 [details]
patch

Attachment 289196 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/2098916

Number of test failures exceeded the failure limit.
Comment 20 Build Bot 2016-09-18 02:41:31 PDT
Created attachment 289200 [details]
Archive of layout-test-results from ews123 for ios-simulator-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 21 Saam Barati 2016-09-18 10:54:00 PDT
Created attachment 289203 [details]
patch

Oops I'm crashing when the VM is deallocated. I need to override operator delete on HasOwnPropertyCache to call fastFree.
Comment 22 WebKit Commit Bot 2016-09-18 10:55:33 PDT
Attachment 289203 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:77:  One line control clauses should not use braces.  [whitespace/braces] [4]
ERROR: Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:104:  Missing space before {  [whitespace/braces] [5]
Total errors found: 2 in 34 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 23 Saam Barati 2016-09-18 10:56:45 PDT
Created attachment 289204 [details]
patch

fix style of `if`
Comment 24 WebKit Commit Bot 2016-09-18 10:58:46 PDT
Attachment 289204 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:103:  Missing space before {  [whitespace/braces] [5]
Total errors found: 1 in 34 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 25 Build Bot 2016-09-18 12:03:59 PDT
Comment on attachment 289204 [details]
patch

Attachment 289204 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/2101127

New failing tests:
fast/dom/Window/forbid-showModalDialog.html
Comment 26 Build Bot 2016-09-18 12:04:05 PDT
Created attachment 289205 [details]
Archive of layout-test-results from ews101 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 27 Build Bot 2016-09-18 12:08:18 PDT
Comment on attachment 289204 [details]
patch

Attachment 289204 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/2101133

New failing tests:
fast/dom/Window/forbid-showModalDialog.html
Comment 28 Build Bot 2016-09-18 12:08:23 PDT
Created attachment 289206 [details]
Archive of layout-test-results from ews106 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 29 Build Bot 2016-09-18 12:11:01 PDT
Comment on attachment 289204 [details]
patch

Attachment 289204 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/2101132

New failing tests:
fast/dom/Window/forbid-showModalDialog.html
Comment 30 Build Bot 2016-09-18 12:11:05 PDT
Created attachment 289207 [details]
Archive of layout-test-results from ews117 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews117  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 31 Build Bot 2016-09-18 12:17:32 PDT
Comment on attachment 289204 [details]
patch

Attachment 289204 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/2101137

New failing tests:
fast/dom/Window/forbid-showModalDialog.html
Comment 32 Build Bot 2016-09-18 12:17:37 PDT
Created attachment 289208 [details]
Archive of layout-test-results from ews124 for ios-simulator-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews124  Port: ios-simulator-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 33 Saam Barati 2016-09-18 13:58:33 PDT
Looks like there is some crazy stuff going on with showModalDialogue in JSDOMWindow. Let me see what's happening there.
Comment 34 Saam Barati 2016-09-18 14:09:11 PDT
I think this patch is still in good shape for review. It's failing just one showModalDialogue test, and I think the bug might actually be in showModalDialogue populating a PropertySlot that claims its cacheable.
Comment 35 Saam Barati 2016-09-18 14:10:12 PDT
(In reply to comment #34)
> I think this patch is still in good shape for review. It's failing just one
> showModalDialogue test, and I think the bug might actually be in
> showModalDialogue populating a PropertySlot that claims its cacheable.

I'm still trying to figure out exactly what to do about this. I'll either work around it in my patch somehow, or I'll make a change to how JSDOMWindow handle's the showModalDialogue property. I suspect it'll be the latter.
Comment 36 Yusuke Suzuki 2016-09-18 21:43:51 PDT
Comment on attachment 289204 [details]
patch

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

> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h:2275
> +#else // CPU(slot) || (CPU(ARM) && CPU(ARM_HARDFP)) || CPU(ARM64) || CPU(MIPS) || CPU(SH4)

Seems incorrect.

> Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:34
> +    static const uint32_t size = 8 * 1024;

Is it necessary to allocate this large size cache?
Comment 37 Saam Barati 2016-09-18 22:52:54 PDT
Comment on attachment 289204 [details]
patch

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

>> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h:2275
>> +#else // CPU(slot) || (CPU(ARM) && CPU(ARM_HARDFP)) || CPU(ARM64) || CPU(MIPS) || CPU(SH4)
> 
> Seems incorrect.

Oops. I'll revert

>> Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:34
>> +    static const uint32_t size = 8 * 1024;
> 
> Is it necessary to allocate this large size cache?

Let me try to mess around with the size again, I only varied the size in the beginning of me writing this patch
Comment 38 Geoffrey Garen 2016-09-19 12:09:39 PDT
Comment on attachment 289204 [details]
patch

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

> Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:69
> +    ALWAYS_INLINE Optional<bool> get(Structure* structure, PropertyName propName)

Is the C++ implementation a win, or should we only have a JIT implementation?

> Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:88
> +        if (!slot.isCacheable() && !slot.isUnset())
> +            return;

Why the && here?

> Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:118
> +ALWAYS_INLINE HasOwnPropertyCache* VM::ensureHasOwnPropertyCache()
> +{
> +    if (UNLIKELY(!m_hasOwnPropertyCache))
> +        m_hasOwnPropertyCache = std::unique_ptr<HasOwnPropertyCache>(HasOwnPropertyCache::create());
> +    return m_hasOwnPropertyCache.get();
> +}

I'm kind of contradicting myself here, but I wonder if the cache should be per-structure instead of global.

Reasons to prefer:

(1) No need to check structure equality on lookup -- faster;

(2) Simpler lifetime rules (similar to property name array cache);

(3) Reduction in collisions -- higher hit rate.

Reasons not to prefer:

(1) Uses more memory if you hasOwnProperty on lots of objects;
Comment 39 Saam Barati 2016-09-19 14:54:25 PDT
Comment on attachment 289204 [details]
patch

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

>> Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:69
>> +    ALWAYS_INLINE Optional<bool> get(Structure* structure, PropertyName propName)
> 
> Is the C++ implementation a win, or should we only have a JIT implementation?

Not sure. I remember not getting a win in speedometer, but I'll see if it helps for micro benchmarks. I'll also run without JIT implementation for speedometer and measure time spent using the sampling profiler, to see if it sees less time spent in HasOwnProperty.

>> Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:88
>> +            return;
> 
> Why the && here?

unset slots always return false from isCacheable. So we're basically asking if it's set and uncacheable.
If it's unset, we have other guards to see if we can cache it below, using `structure->propertyAccessesAreCacheableForAbsence()`.
It might be easier to read the if as:
if (!(slot.isCacheable() || slot.isUnset())) ...

>> Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:118
>> +}
> 
> I'm kind of contradicting myself here, but I wonder if the cache should be per-structure instead of global.
> 
> Reasons to prefer:
> 
> (1) No need to check structure equality on lookup -- faster;
> 
> (2) Simpler lifetime rules (similar to property name array cache);
> 
> (3) Reduction in collisions -- higher hit rate.
> 
> Reasons not to prefer:
> 
> (1) Uses more memory if you hasOwnProperty on lots of objects;

Geoff and I discussed offline another possible use of the cache: It may help property access in other scenarios of we have the cache be used per structure
and we can optimize the memory overhead of Structure's property table by making it an array of sorts and putting the cache in front of it.
If we consider a world where we don't think of the cache being used to optimize other types of property access, and only consider it only
in a world of HasOwnProperty, I think the global cache is strictly faster (at least for the benchmark I'm tuning for in Speedometer, and probably
other real use cases of the HasOwnProperty where it will be unlikely to encounter very many structures in hot invocations of HasOwnProperty).

1) I don't think this will actually be faster since speedometer has about a 92-94% hit rate in the cache. The reason being, we'd need to do three extra
dependent loads and two extra branches: first load the structure from the object, and then to load and check if it has rare data, then to load the cache from the rare data
and check if it is non-null. With a global cache, the machine code we emit just materializes the global cache pointer.

2) Yeah, the rules are probably a bit simpler. They're definitely much cleaner if tied to a Structure's lifetime. However, the lifetime rules now
aren't very complicated either. They're not super elegant, since we just clear the cache on every GC, but I don't think they're too difficult to understand.

3) This will definitely be true, especially for programs that encounter very many structures. I think for programs that don't encounter many structures, it's probably
a toss up. I also think it's likely that most programs won't see very many structure's in a hot hasOwnProperty.

Not to prefer:
1) I think this could go either way actually. If a program encounters very few structures in hasOwnProperty, we will probably save memory. If it encounters many 
Structures, we'll definitely use more memory. However, we'll also get better performance in the case where we encounter very many Structures.
Comment 40 Saam Barati 2016-09-19 15:12:53 PDT
Created attachment 289265 [details]
patch

I think this fixes layout test failures.
Comment 41 WebKit Commit Bot 2016-09-19 15:15:15 PDT
Attachment 289265 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:107:  Missing space before {  [whitespace/braces] [5]
Total errors found: 1 in 35 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 42 Saam Barati 2016-09-19 16:19:36 PDT
Created attachment 289272 [details]
patch

Reduce the cache size to 2*1024. I don't see a reduction in hit rate on Speedometer with this, so it's better to use less memory if possible.
Comment 43 WebKit Commit Bot 2016-09-19 16:21:38 PDT
Attachment 289272 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:107:  Missing space before {  [whitespace/braces] [5]
Total errors found: 1 in 35 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 44 Geoffrey Garen 2016-09-19 16:24:08 PDT
Comment on attachment 289272 [details]
patch

r=me
Comment 45 Saam Barati 2016-09-19 17:43:33 PDT
Created attachment 289293 [details]
patch for landing
Comment 46 WebKit Commit Bot 2016-09-19 17:46:09 PDT
Attachment 289293 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/HasOwnPropertyCache.h:107:  Missing space before {  [whitespace/braces] [5]
Total errors found: 1 in 35 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 47 Saam Barati 2016-09-19 18:08:24 PDT
landed in:
https://trac.webkit.org/changeset/206136
Comment 48 Csaba Osztrogonác 2016-09-20 06:30:39 PDT
(In reply to comment #47)
> landed in:
> https://trac.webkit.org/changeset/206136

There are many failiures on 32 bit bots after this change.
Please see build.webkit.org for details.
Comment 49 Saam Barati 2016-09-20 07:43:50 PDT
(In reply to comment #48)
> (In reply to comment #47)
> > landed in:
> > https://trac.webkit.org/changeset/206136
> 
> There are many failiures on 32 bit bots after this change.
> Please see build.webkit.org for details.

Looking now. Thanks
Comment 50 Saam Barati 2016-09-20 08:22:46 PDT
(In reply to comment #49)
> (In reply to comment #48)
> > (In reply to comment #47)
> > > landed in:
> > > https://trac.webkit.org/changeset/206136
> > 
> > There are many failiures on 32 bit bots after this change.
> > Please see build.webkit.org for details.
> 
> Looking now. Thanks

I know what the fix is, just building a testing locally before committing.
Comment 51 Saam Barati 2016-09-20 08:59:27 PDT
Landed x86 32 bit fix in:
https://trac.webkit.org/changeset/206149