Bug 220627 - [WK2] Bypass NetworkProcess for MessagePort communication within a single WebProcess
Summary: [WK2] Bypass NetworkProcess for MessagePort communication within a single Web...
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks: 220038
  Show dependency treegraph
 
Reported: 2021-01-14 11:46 PST by Chris Dumez
Modified: 2021-01-14 17:07 PST (History)
8 users (show)

See Also:


Attachments
WIP Patch (10.76 KB, patch)
2021-01-14 11:48 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (14.80 KB, patch)
2021-01-14 11:53 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (15.33 KB, patch)
2021-01-14 12:06 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-01-14 11:46:43 PST
Bypass NetworkProcess for MessagePort communication within a single WebProcess. When the 2 MessagePorts are within the same WebProcess, there is no reason to go via the NetworkProcess to do the communication. Doing so is bad for performance and also loses functionality because SerializedScriptValue is not able to encode everything over IPC (e.g. Wasm modules, see Bug 220038).
Comment 1 Chris Dumez 2021-01-14 11:48:19 PST
Created attachment 417635 [details]
WIP Patch
Comment 2 Chris Dumez 2021-01-14 11:53:21 PST
Created attachment 417636 [details]
Patch
Comment 3 Chris Dumez 2021-01-14 12:06:58 PST
Created attachment 417639 [details]
Patch
Comment 4 Chris Dumez 2021-01-14 13:25:28 PST
Comment on attachment 417639 [details]
Patch

Sadly, this is not as easy as it looks. Current patch breaks cross-process communication (used by service workers). A given WebProcess does not seem to know if its remote MessagePort is within its process or not.
Comment 5 Chris Dumez 2021-01-14 16:50:44 PST
I tried a different approach but it is tricky. At the time a message is posted, we may not know yet if the destination MessagePort will be in the same WebProcess or not.

You can send a MessagePort to a worker and call postMessage() on this MessagePort, before the Worker has received the port (so before entanglement has happened). Entanglement is when we know if both ends of the channel are in the same process.