Open Bug 1587752 Opened 5 years ago Updated 2 years ago

Optimize same-process MessageChannel / MessagePort usage - MessagePort.postMessage transferList has no performance benefit

Categories

(Core :: DOM: Workers, enhancement, P3)

69 Branch
enhancement

Tracking

()

UNCONFIRMED

People

(Reporter: james, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36

Steps to reproduce:

Create a message channel.
Create two workers, and set up the workers to use the message ports from the channel.
From one worker, post messages on its message port with a large array buffer. Include the array buffer in the transfer list:

let arr = new Uint8Array(1024 * 1024 * 10);
this._port.postMessage(arr.buffer, [arr.buffer]);

Measure the time from posting the message to receiving the message.

Actual results:

Including the large array buffer in the transfer list has no effect on performance. The delivery time is identical if the array is cloned or transferred. The transferred items are correctly rendered unusable from the sender though.

On my PC, the time taken to deliver the 10MB buffer is about 100ms, regardless of whether the transfer list is used. Clearly this becomes problematic if we're trying to deliver as close to real time as possible.

Expected results:

With the array specified in the transfer list, the time taken to deliver the simple message should have been closer to 0ms.

Hi James,

Thank you for your report and for the info you provided.

As a starting point, I'll add a product and component so the corresponding dev team can take a look at this, but feel free to change it for a more appropriate one.

In the meantime, please download Firefox Nightly and let us know if this issue is also reproducible. You can download it from here: https://nightly.mozilla.org/

Regards,

Component: Untriaged → IPC
Flags: needinfo?(james)
Product: Firefox → Core

Hi Virginia,

I can confirm the problem exists with the Nightly build of Firefox downloaded from the above link. I've attached a screen shot of the console output showing no difference in timings between a postMessage using clone and postMessage using transfers.

Thanks,

James

Flags: needinfo?(james)
Attached image test code output
Component: IPC → DOM: Core & HTML
Component: DOM: Core & HTML → DOM: Workers

A current limitation is that only Worker.postMessage() and DedicatedWorkerGlobalScope.postMessage() have same-process optimizations. Everything else roundtrips the data through PBackground in the parent process.

With recent changes to IPC to allow for improved end-point shipping and enhanced support for same-process actors in this situation, it's possible IPC might do some of the heavy lifting here.

Type: defect → enhancement
Priority: -- → P3
Summary: MessagePort.postMessage transferList has no performance benefit → Optimize same-process MessageChannel / MessagePort usage - MessagePort.postMessage transferList has no performance benefit
See Also: → 1360190

I can confirm the issue. Browser crashes with out of memory when large ArrayBuffer is transfered via MessagePort. Looks like buffer is duplicated, while is should not be.

Severity: normal normal → S3 S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: