Bug 211112

Summary: Reduce IPC overhead for message receiver name and message name to 2 bytes
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: New BugsAssignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: aboya, andersca, annulen, Basuke.Suzuki, benjamin, cdumez, cgarcia, cmarcelo, cturner, darin, ddkilzer, don.olmstead, eric.carlson, ews-watchlist, glenn, gyuyoung.kim, jer.noble, mcatanzaro, mkwst, philipj, pnormand, rwlbuis, ryuan.choi, sam, sergio, sihui_liu, svillar, useafterfree, vjaquez, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=213751
https://bugs.webkit.org/show_bug.cgi?id=215054
https://bugs.webkit.org/show_bug.cgi?id=215064
Bug Depends on: 211826    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch CMake
none
Patch CMake
none
Patch
none
Patch
none
patch
none
Patch
none
Patch
none
Patch none

Description Alex Christensen 2020-04-27 18:55:08 PDT
Reduce IPC overhead for message receiver name and message name to 2 bytes
Comment 1 Alex Christensen 2020-04-27 18:55:49 PDT
Created attachment 397783 [details]
Patch
Comment 2 Alex Christensen 2020-04-27 22:13:19 PDT
Created attachment 397806 [details]
Patch
Comment 3 Alex Christensen 2020-04-27 22:19:40 PDT
Created attachment 397807 [details]
Patch
Comment 4 Alex Christensen 2020-04-27 23:57:13 PDT
Created attachment 397815 [details]
Patch
Comment 5 Alex Christensen 2020-04-28 08:43:29 PDT
Created attachment 397841 [details]
Patch
Comment 6 Alex Christensen 2020-04-28 09:09:06 PDT
Don, could you get this working with CMake/Windows?  I've changed the parameters to the message generators and added MessageNames.h and MessageNames.cpp.
Comment 7 Sihui Liu 2020-04-28 09:22:14 PDT
Comment on attachment 397841 [details]
Patch

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

> Source/WebKit/Scripts/MessageNames.h:33
> +    WebPage = 1
> +    , WebPage = 2

Looks like duplicate?
Comment 8 Alex Christensen 2020-04-28 09:31:11 PDT
That's fine.  That's because the test receivers have multiple receivers with the same name.  That file is just to test the generator.
Comment 9 Michael Catanzaro 2020-04-28 16:21:26 PDT
Looks like it's trying to build GPUProcessMessageReceiver.cpp. Probably missing an #if ENABLE(GPU_PROCESS) check somewhere?

[585/1094] Generating ../../DerivedSources/WebKit/GPUProcessMessageReceiver.cpp, ../../DerivedSources/WebKit/GPUProcessMessages.h, ../../DerivedSources/WebKit/GPUProcessMessagesReplies.h
FAILED: DerivedSources/WebKit/GPUProcessMessageReceiver.cpp DerivedSources/WebKit/GPUProcessMessages.h DerivedSources/WebKit/GPUProcessMessagesReplies.h 
cd /home/ews/worker/GTK-Build-EWS/build/Source/WebKit && /usr/bin/python2.7 /home/ews/worker/GTK-Build-EWS/build/Source/WebKit/Scripts/generate-message-receiver.py GPUProcess/GPUProcess.messages.in --implementation /home/ews/worker/GTK-Build-EWS/build/WebKitBuild/Release/DerivedSources/WebKit/GPUProcessMessageReceiver.cpp --header /home/ews/worker/GTK-Build-EWS/build/WebKitBuild/Release/DerivedSources/WebKit/GPUProcessMessages.h --reply-header /home/ews/worker/GTK-Build-EWS/build/WebKitBuild/Release/DerivedSources/WebKit/GPUProcessMessagesReplies.h
Generating message receiver for --implementation
Traceback (most recent call last):
  File "/home/ews/worker/GTK-Build-EWS/build/Source/WebKit/Scripts/generate-message-receiver.py", line 72, in <module>
    sys.exit(main(sys.argv))
  File "/home/ews/worker/GTK-Build-EWS/build/Source/WebKit/Scripts/generate-message-receiver.py", line 50, in main
    with open('%s/%s.messages.in' % (base_dir, parameter)) as source_file:
IOError: [Errno 20] Not a directory: 'GPUProcess/GPUProcess.messages.in/--implementation.messages.in'
Comment 10 Alex Christensen 2020-04-28 16:49:09 PDT
The point of me cc'ing people who work on GTK was that this will take a bit more effort than I can do just looking at EWS.  generate-message-receiver.py used to be invoked for each .messages.in file with --implementation, --header, and --reply-header in argv, and this requires changing the CMake files to call generate-message-receiver.py with the Source/WebKit directory then a complete list of all the .messages.in files without the .messages.in suffix.  Could someone get that working on Linux?
Comment 11 Michael Catanzaro 2020-04-28 17:47:08 PDT
It's the sort of thing I would have made time for back when I worked at Igalia, but I'm swamped with non-WebKit tasks right now. Somebody else will probably help.
Comment 12 Don Olmstead 2020-04-30 11:08:31 PDT
(In reply to Alex Christensen from comment #10)
> The point of me cc'ing people who work on GTK was that this will take a bit
> more effort than I can do just looking at EWS.  generate-message-receiver.py
> used to be invoked for each .messages.in file with --implementation,
> --header, and --reply-header in argv, and this requires changing the CMake
> files to call generate-message-receiver.py with the Source/WebKit directory
> then a complete list of all the .messages.in files without the .messages.in
> suffix.  Could someone get that working on Linux?

Hey Alex,

One issue I foresee with this particular change is that you're going to hit the windows command line limit of 32767 characters. Can you have it so this script can take the values from a file?

https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation
Comment 13 Alex Christensen 2020-04-30 11:40:06 PDT
The parameters are python (maybe with a full path), path to generate-message-receiver.py, path to Source/WebKit directory, then a list of relative paths to all the .messages.in files, which is currently 5385 characters.  So unless you're using 9kb paths, you should be fine.  If someone runs up against the limit we can fix it, but I don't foresee that happening.
Comment 14 Alex Christensen 2020-05-01 12:40:02 PDT
Adding all Igalia accounts who have committed to WebKit in the last few days.
Comment 15 Don Olmstead 2020-05-01 13:57:43 PDT Comment hidden (obsolete)
Comment 16 Don Olmstead 2020-05-01 15:00:32 PDT
Created attachment 398245 [details]
Patch CMake
Comment 17 Don Olmstead 2020-05-01 15:18:37 PDT
Comment on attachment 398245 [details]
Patch CMake

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

I checked with WinCairo and incremental builds work and everything links. There was a bug in the previous patch where it wasn't iterating through the list.

Source/WebKit/UIProcess/LegacySessionStateCodingNone.cpp still doesn't compile but I just commented out the offending code to test the build bits.

> Source/WebKit/CMakeLists.txt:416
> +        list(APPEND _outputs

Think maybe _outputs should be _output_files for symmetry with the _input_files variable.

> Source/WebKit/CMakeLists.txt:429
> +            ${_outputs}

Ditto
Comment 18 Alex Christensen 2020-05-01 15:24:49 PDT
Created attachment 398252 [details]
Patch
Comment 19 Alex Christensen 2020-05-01 16:46:33 PDT
Created attachment 398262 [details]
Patch
Comment 20 Philippe Normand 2020-05-02 03:01:16 PDT
diff --git a/Source/WebKit/UIProcess/LegacySessionStateCodingNone.cpp b/Source/WebKit/UIProcess/LegacySessionStateCodingNone.cpp                                                                                  
index a1ef8d6df672..762f55ed5c9e 100644
--- a/Source/WebKit/UIProcess/LegacySessionStateCodingNone.cpp
+++ b/Source/WebKit/UIProcess/LegacySessionStateCodingNone.cpp
@@ -39,7 +39,7 @@ namespace WebKit {
 RefPtr<API::Data> encodeLegacySessionState(const SessionState& sessionState)
 {
     // FIXME: This should use WTF::Persistence::Encoder instead.
-    IPC::Encoder encoder(MessageName::LegacySessionState, 0);
+    IPC::Encoder encoder(IPC::MessageName::LegacySessionState, 0);
     encoder << sessionState.backForwardListState;
     encoder << sessionState.renderTreeSize;
     encoder << sessionState.provisionalURL;
Comment 21 Philippe Normand 2020-05-02 03:02:49 PDT
Nice palindrome bug BTW :)
Comment 22 Alex Christensen 2020-05-04 10:45:55 PDT
Created attachment 398390 [details]
patch
Comment 23 Chris Dumez 2020-05-05 12:02:45 PDT
Comment on attachment 398390 [details]
patch

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

> Source/WebKit/Platform/IPC/Connection.cpp:1002
> +    auto it = m_workQueueMessageReceivers.find(static_cast<uint8_t>(message->messageReceiverName()));

Why do we have all these new static casts? Can they be avoided?

> Source/WebKit/Platform/IPC/Connection.h:349
> +    using WorkQueueMessageReceiverMap = HashMap<uint8_t, std::pair<RefPtr<WorkQueue>, RefPtr<WorkQueueMessageReceiver>>>;

Can we use a stricter type here than uint8_t?

> Source/WebKit/Platform/IPC/Connection.h:353
> +    using ThreadMessageReceiverMap = HashMap<uint8_t, RefPtr<ThreadMessageReceiver>>;

ditto.

> Source/WebKit/Platform/IPC/MessageReceiverMap.h:59
> +    HashMap<uint8_t, MessageReceiver*> m_globalMessageReceivers;

ditto.

> Source/WebKit/Platform/IPC/MessageReceiverMap.h:61
> +    HashMap<std::pair<uint8_t, uint64_t>, MessageReceiver*> m_messageReceivers;

ditto.
Comment 24 Alex Christensen 2020-05-05 12:04:53 PDT
We could avoid all these casts if we could have a HashMap with an enum type as a key.  I bet we could do it in HashMap by just using std::underlying_type and some static_asserts with isValidKey, but this is the best we can do until that change.  Maybe we should do that change first?

What do you mean by a stricter type?
Comment 25 Chris Dumez 2020-05-05 12:05:40 PDT
(In reply to Alex Christensen from comment #24)
> We could avoid all these casts if we could have a HashMap with an enum type
> as a key.  I bet we could do it in HashMap by just using
> std::underlying_type and some static_asserts with isValidKey, but this is
> the best we can do until that change.  Maybe we should do that change first?
> 
> What do you mean by a stricter type?

I mean the enum type rather than its underlying type.
Comment 26 Chris Dumez 2020-05-05 12:08:50 PDT
(In reply to Alex Christensen from comment #24)
> We could avoid all these casts if we could have a HashMap with an enum type
> as a key.  I bet we could do it in HashMap by just using
> std::underlying_type and some static_asserts with isValidKey, but this is
> the best we can do until that change.  Maybe we should do that change first?

I suggest looking into StrongEnumHashTraits which I believe is used for this purpose.

> 
> What do you mean by a stricter type?
Comment 27 Alex Christensen 2020-05-06 09:54:04 PDT
Created attachment 398631 [details]
Patch
Comment 28 Chris Dumez 2020-05-06 10:19:48 PDT
EWS is very red.
Comment 29 Alex Christensen 2020-05-06 11:52:34 PDT
Created attachment 398641 [details]
Patch
Comment 30 Alex Christensen 2020-05-06 12:14:04 PDT
Created attachment 398644 [details]
Patch
Comment 31 Chris Dumez 2020-05-06 13:57:31 PDT
Comment on attachment 398644 [details]
Patch

r=me
Comment 32 EWS 2020-05-06 15:54:26 PDT
Committed r261254: <https://trac.webkit.org/changeset/261254>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 398644 [details].
Comment 33 Radar WebKit Bug Importer 2020-05-06 15:55:20 PDT
<rdar://problem/62949317>
Comment 34 Ryan Haddad 2020-05-06 20:57:36 PDT
(In reply to EWS from comment #32)
> Committed r261254: <https://trac.webkit.org/changeset/261254>
This appears to have broken webkitpy tests on the bots:
IOError: [Errno 2] No such file or directory: '/Volumes/Data/slave/catalina-release-tests-wk1/build/Source/WebKit/Scripts/webkit/test-messages.in'

https://build.webkit.org/builders/Apple-Catalina-Release-WK1-Tests/builds/5594
Comment 35 Alex Christensen 2020-05-06 23:36:30 PDT
http://trac.webkit.org/r261270
Comment 36 Chris Dumez 2020-05-12 18:01:20 PDT
Comment on attachment 398644 [details]
Patch

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

> Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:-82
> -    m_client.paymentCoordinatorAddMessageReceiver(*this, Messages::WebPaymentCoordinatorProxy::messageReceiverName(), *this);

Who adds the message receiver now? I suspect this may be the cause of <rdar://problem/63161750>
Comment 37 Chris Dumez 2020-05-12 19:01:15 PDT
(In reply to Chris Dumez from comment #36)
> Comment on attachment 398644 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=398644&action=review
> 
> > Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:-82
> > -    m_client.paymentCoordinatorAddMessageReceiver(*this, Messages::WebPaymentCoordinatorProxy::messageReceiverName(), *this);
> 
> Who adds the message receiver now? I suspect this may be the cause of
> <rdar://problem/63161750>

It was the reason. Fixing via https://bugs.webkit.org/show_bug.cgi?id=211826.
Comment 38 Darin Adler 2020-08-02 19:36:49 PDT
There were two mistakes in this patch that led to a super-strange problem where generated files were malformed:

1) The rule in DerivedSources.make has multiple targets; so it needs to be a pattern rule, which is the kind of rule that make handles multiple targets correctly for. The rule was a pattern rule before this patch, but since there wasn’t a comment explaining that was important, this patch changed it to a non-pattern rule. This meant that the rule could run multiple times in parallel. Since make re-checks modification dates after running, it doesn’t always run once per generated file but in theory it could! Keith Rollin figured out it was running multiple times and fixed it in bug 215054.

2) There was a typo "addsufix" so the Messages.h files were not properly identified as targets to make. Make silently ignored the entire thing. I noticed the typo was the reason the files weren’t being regenerated on my computer when I deleted one and fixed it in bug 215064.

We should probably follow up by adding a comment to the makefile explaining why the rule needs to be a pattern rule.
Comment 39 Alex Christensen 2020-08-03 09:32:37 PDT
Make is such a strange language.  Thanks for fixing it.