RESOLVED FIXED 176010
[DFG] Optimize WeakMap::get by adding intrinsic and fixup
https://bugs.webkit.org/show_bug.cgi?id=176010
Summary [DFG] Optimize WeakMap::get by adding intrinsic and fixup
Yusuke Suzuki
Reported 2017-08-26 22:23:12 PDT
It turns out that Ember.js non-debug takes 1% for WeakMap::get()!
Attachments
Patch (44.47 KB, patch)
2017-08-26 23:38 PDT, Yusuke Suzuki
no flags
Patch (48.37 KB, patch)
2017-08-26 23:44 PDT, Yusuke Suzuki
no flags
Patch (45.68 KB, patch)
2017-08-26 23:57 PDT, Yusuke Suzuki
no flags
Patch (45.56 KB, patch)
2017-08-27 00:12 PDT, Yusuke Suzuki
no flags
Patch (54.21 KB, patch)
2017-08-30 01:32 PDT, Yusuke Suzuki
no flags
Patch (58.12 KB, patch)
2017-09-03 22:37 PDT, Yusuke Suzuki
fpizlo: review+
Patch for landing (59.56 KB, patch)
2017-09-12 10:22 PDT, Yusuke Suzuki
no flags
Yusuke Suzuki
Comment 1 2017-08-26 23:38:30 PDT
Build Bot
Comment 2 2017-08-26 23:39:52 PDT
Attachment 319153 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGNodeType.h:439: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] Total errors found: 1 in 33 files If any of these errors are false positives, please file a bug against check-webkit-style.
Yusuke Suzuki
Comment 3 2017-08-26 23:44:19 PDT
Build Bot
Comment 4 2017-08-26 23:47:12 PDT
Attachment 319154 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGNodeType.h:439: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] Total errors found: 1 in 34 files If any of these errors are false positives, please file a bug against check-webkit-style.
Yusuke Suzuki
Comment 5 2017-08-26 23:57:20 PDT
Build Bot
Comment 6 2017-08-26 23:58:30 PDT
Attachment 319155 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGNodeType.h:439: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] Total errors found: 1 in 34 files If any of these errors are false positives, please file a bug against check-webkit-style.
Yusuke Suzuki
Comment 7 2017-08-27 00:12:21 PDT
Build Bot
Comment 8 2017-08-27 00:14:46 PDT
Attachment 319157 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGNodeType.h:439: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] Total errors found: 1 in 34 files If any of these errors are false positives, please file a bug against check-webkit-style.
Yusuke Suzuki
Comment 9 2017-08-30 01:32:41 PDT
Build Bot
Comment 10 2017-08-30 01:35:07 PDT
Attachment 319355 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGNodeType.h:439: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] Total errors found: 1 in 38 files If any of these errors are false positives, please file a bug against check-webkit-style.
Darin Adler
Comment 11 2017-09-03 21:55:51 PDT
Comment on attachment 319355 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=319355&action=review > Source/JavaScriptCore/ChangeLog:15 > + 1. We use fastGet to inline WeakMap#get operation in the native function. > + Since this native function itself is very small, we should inline HashMap#get > + entirely in this function. Can we call this inlinedGet or inlineGet?
Yusuke Suzuki
Comment 12 2017-09-03 22:34:07 PDT
Comment on attachment 319355 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=319355&action=review >> Source/JavaScriptCore/ChangeLog:15 >> + entirely in this function. > > Can we call this inlinedGet or inlineGet? OK, renamed.
Yusuke Suzuki
Comment 13 2017-09-03 22:37:02 PDT
Build Bot
Comment 14 2017-09-03 22:40:02 PDT
Attachment 319839 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGNodeType.h:437: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] Total errors found: 1 in 42 files If any of these errors are false positives, please file a bug against check-webkit-style.
Yusuke Suzuki
Comment 15 2017-09-09 10:16:47 PDT
Comment on attachment 319839 [details] Patch Ping?
Darin Adler
Comment 16 2017-09-10 12:38:48 PDT
Comment on attachment 319839 [details] Patch I’d love to review but I am likely not familiar enough with JIT type speculation details to know if it is complete. In other words, I can’t really review the part of this in the bytecode, dfg, and jit directories. The part in the runtime and wtf directories look great to me (as well as the changes to rename fastGet to inlineGet), so consider those reviewed.
Filip Pizlo
Comment 17 2017-09-10 13:10:21 PDT
Comment on attachment 319839 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=319839&action=review R=me other than the AI issue. > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1077 > + forNode(node).makeBytecodeTop(); Why bytecode top? Isn’t this heap top? (It cannot return empty)
Yusuke Suzuki
Comment 18 2017-09-11 01:17:25 PDT
Comment on attachment 319839 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=319839&action=review >> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1077 >> + forNode(node).makeBytecodeTop(); > > Why bytecode top? > > Isn’t this heap top? > > (It cannot return empty) Oops, right. Fixed.
Yusuke Suzuki
Comment 19 2017-09-11 01:19:48 PDT
Saam Barati
Comment 21 2017-09-11 12:11:08 PDT
Comment on attachment 319839 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=319839&action=review LGTM too. Just a couple of comments > Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:2988 > + Node* hash = addToGraph(MapHash, key); WeakMap uses the same hash as Map/Set? I guess we're relying on WTF::HashMap using Wang's int64 hash for objects? I feel like we should perhaps provide a hash inside WeakMapBase to make this explicit. > Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:10361 > + m_jit.exceptionCheck(); is this actually possible?
Saam Barati
Comment 22 2017-09-11 12:13:06 PDT
Comment on attachment 319839 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=319839&action=review >> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:2988 >> + Node* hash = addToGraph(MapHash, key); > > WeakMap uses the same hash as Map/Set? I guess we're relying on WTF::HashMap using Wang's int64 hash for objects? I feel like we should perhaps provide a hash inside WeakMapBase to make this explicit. To expand a bit more on this, I want the freedom to change what MapHash does, along with the hash we use for JSMap/JSSet without having to change things in WTF. I was actually thinking of looking into this again recently. I think we can probably find something cheaper than Wang's int64 hash that's still good enough for JSMap/JSSet's needs. That's why I think we should explicitly pass a traits that defines a hash for WeakMapBase.
Ryan Haddad
Comment 23 2017-09-11 14:11:39 PDT
Reverted r221854 for reason: The test added with this change fails on 32-bit JSC bots. Committed r221876: <http://trac.webkit.org/changeset/221876>
Yusuke Suzuki
Comment 24 2017-09-12 09:57:45 PDT
Comment on attachment 319839 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=319839&action=review >>> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:2988 >>> + Node* hash = addToGraph(MapHash, key); >> >> WeakMap uses the same hash as Map/Set? I guess we're relying on WTF::HashMap using Wang's int64 hash for objects? I feel like we should perhaps provide a hash inside WeakMapBase to make this explicit. > > To expand a bit more on this, I want the freedom to change what MapHash does, along with the hash we use for JSMap/JSSet without having to change things in WTF. I was actually thinking of looking into this again recently. I think we can probably find something cheaper than Wang's int64 hash that's still good enough for JSMap/JSSet's needs. That's why I think we should explicitly pass a traits that defines a hash for WeakMapBase. Sounds nice. Yeah, we are currently using wang's hash function for HashMap. So functionality itself is ok. I'll add an explicit HashFunction for WeakMap/Set's HashMap. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:10361 >> + m_jit.exceptionCheck(); > > is this actually possible? We can drop this check. Dropped in a relanding patch.
Yusuke Suzuki
Comment 25 2017-09-12 10:00:58 PDT
(In reply to Ryan Haddad from comment #23) > Reverted r221854 for reason: > > The test added with this change fails on 32-bit JSC bots. > > Committed r221876: <http://trac.webkit.org/changeset/221876> OK, 32bit is failing because MapHash is calculated against 64bit (JSValue bit pattern), while our HashMap uses 32bit pointer hash.
Yusuke Suzuki
Comment 26 2017-09-12 10:22:53 PDT
Created attachment 320554 [details] Patch for landing
Build Bot
Comment 27 2017-09-12 10:25:50 PDT
Attachment 320554 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGNodeType.h:440: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] Total errors found: 1 in 43 files If any of these errors are false positives, please file a bug against check-webkit-style.
Yusuke Suzuki
Comment 28 2017-09-13 00:02:32 PDT
Radar WebKit Bug Importer
Comment 29 2017-09-27 12:54:05 PDT
Note You need to log in before you can comment on or make changes to this bug.