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).
Created attachment 417635 [details] WIP Patch
Created attachment 417636 [details] Patch
Created attachment 417639 [details] Patch
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.
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.