Open Bug 1473828 Opened 2 years ago Updated 1 year ago

RDP packets are wrapped in a compartment different from the module loader one


(DevTools :: Framework, defect, P2)



(Not tracked)


(Reporter: ochameau, Assigned: ochameau)


(Blocks 2 open bugs)



(1 file)

While looking at performance regression of bug 1471853 (regression due to browser loader), it occurs to me that RDP packets and especially the "attributes" one from the inspector actors are coming form another compartment (it is hard to say which one) and so it causes to involve cross compartment wrapper anytime we query any packet.

Here is a profile of DAMP on mozilla-central, when running

Let's focus on getAttribute
function getAttribute(attributes, attributeName) {
  for (const {name, value} of attributes) {
    if (name === attributeName) {
      return value;
  return null;

You see that this simple function has to cross compartments when accessing `attributes`. This attributes is some data sent by the inspector actor, it ultimately comes from this function within the transport layer:
When node-attribute-parser is loaded in the main devtools loader, both transport.js and node-attribute-parser.js should be loaded in the same compartment and do not have any overhead related to wrappers.
So it looks like the `data` object passe to `receiveMessage` is bound to some other compartment, may be the tab child global? I'm not sure how to assert that.
But I think that this relates to 1449231.

Based on that, I tried using StructuredCloneHolder to ensure wrapping the packets in the right compartment, the main loader compartment. It has a significant and very positive impact on the inspector, but it regresses the protocoljs test and debugger stepIn:
Assignee: nobody → poirot.alex
Depends on: 1474843
For some reason I can't really explain, using StructuredCloneHolder manually like this was introducing an overhead at GC level as if we had an overhead while destroying the previous packets.

But I found out that messageManager.addWeakMessageListener did not regressed from bug 1449231
and that we can recover the right compartment for RDP packets:
This time only panelsInBackground regressed, but I'll assume that just because of tests overlap.
Comment on attachment 8990233 [details]
Bug 1473828 - Use weak message manager listener to have message data be in sandbox compartment.

Wait, I'm still looking forward a green try before going for review.
I may also clean things up around worker and transport.js as that's full of historical cruft.
Attachment #8990233 - Flags: review?(jryans)
Depends on: 1000814
Depends on: 1474980
Priority: -- → P2
For some reason, it breaks the responsive design.
I tried hacking into tunnel.js without much success yet.

Note that this patch is now based on top of bug 1000814 and bug 1474980.
The tunnel currently skips weak listeners and just passes them through, so that sounds related, but I guess that's the part you tried adjusting...  Anyway, maybe it's better to fix the core issue with compartments directly?
You need to log in before you can comment on or make changes to this bug.