Bug 155552 - Implement SmallPtrSet and integrate it into the Parser
Summary: Implement SmallPtrSet and integrate it into the Parser
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:
Blocks:
 
Reported: 2016-03-16 11:52 PDT by Saam Barati
Modified: 2016-03-20 13:02 PDT (History)
12 users (show)

See Also:


Attachments
WIP (19.05 KB, patch)
2016-03-17 02:06 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
perf numbers (69.43 KB, text/plain)
2016-03-17 15:24 PDT, Saam Barati
no flags Details
patch (28.15 KB, patch)
2016-03-17 17:32 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (28.84 KB, patch)
2016-03-17 17:37 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (28.83 KB, patch)
2016-03-17 17:42 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (28.85 KB, patch)
2016-03-17 17:44 PDT, Saam Barati
fpizlo: review+
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-03-16 11:52:18 PDT
This data structure will use an inline array when the set is small.
It won't have a remove operation.
This should help speed up some of the HashSets we use inside the parser.
It'll also be helpful in other places.

See http://llvm.org/docs/doxygen/html/SmallPtrSet_8h_source.html
Comment 1 Saam Barati 2016-03-17 02:06:04 PDT
Created attachment 274272 [details]
WIP

might be ready.
Comment 2 Saam Barati 2016-03-17 02:06:26 PDT
I've been getting about a 1.5-2.5% octane/code-load speed up from this.
Comment 3 Saam Barati 2016-03-17 15:24:27 PDT
Created attachment 274328 [details]
perf numbers

looks like a code-load progression.
Will post patch soon.
Comment 4 Saam Barati 2016-03-17 17:32:44 PDT
Created attachment 274344 [details]
patch
Comment 5 Saam Barati 2016-03-17 17:33:43 PDT
Comment on attachment 274344 [details]
patch

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

> Source/JavaScriptCore/parser/Parser.h:195
> +    Scope(Scope&& rhs)

Actually, with vector.constructAndAppend(...) we don't need this.
I'm removing it locally.

I'm also adding a comment at the top of the fields inside Scope saying
that they must be movable through memcpy.
Comment 6 WebKit Commit Bot 2016-03-17 17:34:42 PDT
Attachment 274344 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/SmallPtrSet.h:113:  Multi line control clauses should use braces.  [whitespace/braces] [4]
ERROR: Source/WTF/wtf/SmallPtrSet.h:243:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 2 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Saam Barati 2016-03-17 17:37:52 PDT
Created attachment 274345 [details]
patch
Comment 8 WebKit Commit Bot 2016-03-17 17:39:18 PDT
Attachment 274345 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/SmallPtrSet.h:113:  Multi line control clauses should use braces.  [whitespace/braces] [4]
ERROR: Source/WTF/wtf/SmallPtrSet.h:243:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 2 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Saam Barati 2016-03-17 17:42:15 PDT
Created attachment 274346 [details]
patch
Comment 10 WebKit Commit Bot 2016-03-17 17:44:00 PDT
Attachment 274346 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/SmallPtrSet.h:113:  Multi line control clauses should use braces.  [whitespace/braces] [4]
Total errors found: 1 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 11 Saam Barati 2016-03-17 17:44:41 PDT
Created attachment 274347 [details]
patch
Comment 12 WebKit Commit Bot 2016-03-17 17:46:54 PDT
Attachment 274347 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/SmallPtrSet.h:113:  Multi line control clauses should use braces.  [whitespace/braces] [4]
Total errors found: 1 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Saam Barati 2016-03-17 19:11:50 PDT
landed in:
http://trac.webkit.org/changeset/198375
Comment 14 Sam Weinig 2016-03-17 20:03:20 PDT
Would there be value in trying to add this optimization (perhaps optionally using traits) to our HashMap/HashSet code? Presumably this optimization could be useful in other places, where they weren't necessarily storing pointers.

Also, is the reason you don't support remove to avoid having a branch for a deleteValue sentinel?
Comment 15 Oliver Hunt 2016-03-17 23:33:05 PDT
Comment on attachment 274347 [details]
patch

I would rather have had the inline size be a template parameter (as we do for other data structures) - we could give a default capacity so the general behaviour wouldn't be impacted.
Comment 16 Geoffrey Garen 2016-03-18 11:56:19 PDT
Comment on attachment 274347 [details]
patch

Longer-term, it would be nice to have inline capacity as an option in WTF::HashSet and WTF::HashMap. Perhaps the optimizations you've added for never removing, linear scanning, and memcpy are fundamentally incompatible with those more flexible data structures. But maybe not.
Comment 17 Saam Barati 2016-03-20 12:58:06 PDT
(In reply to comment #14)
> Would there be value in trying to add this optimization (perhaps optionally
> using traits) to our HashMap/HashSet code? Presumably this optimization
> could be useful in other places, where they weren't necessarily storing
> pointers.
> 
> Also, is the reason you don't support remove to avoid having a branch for a
> deleteValue sentinel?

I think it's worth experimenting with some inline capacity inside HashMap/HashSet.
I'm sure there are places where this would really help out.

Not supporting remove() does remove a branch, but it also simplifies some
of the assumptions made in the code. It wouldn't be that difficult to add support
for remove, but I'm hesitant to do it. I really want this data structure to
be as simple as possible.

I think one place where it might be worth adding some complexity is in supporting
smart pointers. I don't think it'd be that difficult to do.
Comment 18 Saam Barati 2016-03-20 12:59:07 PDT
(In reply to comment #15)
> Comment on attachment 274347 [details]
> patch
> 
> I would rather have had the inline size be a template parameter (as we do
> for other data structures) - we could give a default capacity so the general
> behaviour wouldn't be impacted.

I think this is worth doing at some point. It seems like a good patch
to do when we find code that needs it. LLVM's implementation does support
inline capacity as a template parameter.
Comment 19 Saam Barati 2016-03-20 13:02:42 PDT
(In reply to comment #16)
> Comment on attachment 274347 [details]
> patch
> 
> Longer-term, it would be nice to have inline capacity as an option in
> WTF::HashSet and WTF::HashMap. Perhaps the optimizations you've added for
> never removing, linear scanning, and memcpy are fundamentally incompatible
> with those more flexible data structures. But maybe not.

I'm not sure. I would have to familiarize myself more with the details
of how HashMap/HashSet are implemented. I'm sure it would be possible
to add inline capacity to HashMap/HashSet in some form, but maybe it
wouldn't be exactly as it is implemented here. For example, HashMap/HashSet
support remove, so when we're in small mode and we perform contains(.) we will 
have to traverse the entire inline array instead of just up to m_size.