Closed
Bug 1348095
Opened 8 years ago
Closed 8 years ago
Can we cache the proto for DOM Xrays?
Categories
(Core :: XPConnect, enhancement)
Core
XPConnect
Tracking
()
RESOLVED
FIXED
mozilla55
Tracking | Status | |
---|---|---|
firefox55 | --- | fixed |
People
(Reporter: bzbarsky, Assigned: bzbarsky)
References
(Blocks 1 open bug)
Details
Attachments
(3 files)
1019 bytes,
patch
|
bholley
:
review+
|
Details | Diff | Splinter Review |
4.30 KB,
patch
|
bholley
:
review+
|
Details | Diff | Splinter Review |
2.58 KB,
patch
|
bholley
:
review+
|
Details | Diff | Splinter Review |
I was playing with the testcase in bug 613498 a bit, and the profile shows a quarter of the time under Xray access to DOM objects being XrayWrapper<CrossCompartmentWrapper, DOMXrayTraits>::getPrototype.
This is not surprising; for a .nextSibling access on an element we have to do at least 4 getPrototype calls (element-specific proto, HTMLElement.prototype, Element.prototype, Node.prototype) before we find the property. And each call is not that cheap, not least because it has to JS_WrapObject.
But the proto of a DOM Xray should be immutable, right? Could we just store it in a slot after we get it the first time, perhaps?
Flags: needinfo?(bobbyholley)
Comment 1•8 years ago
|
||
(In reply to Boris Zbarsky [:bz] (still a bit busy) (if a patch has no decent message, automatic r-) from comment #0)
> But the proto of a DOM Xray should be immutable, right?
Nope, see the JSSLOT_EXPANDO_PROTOTYPE stuff at http://searchfox.org/mozilla-central/rev/0079c7adf3b329bff579d3bbe6ac7ba2f6218a19/js/xpconnect/wrappers/XrayWrapper.cpp#2413
> Could we just store
> it in a slot after we get it the first time, perhaps?
So, we already have the slot on the expando object, and could cache it there (assuming the Xray hook always returns the same result), at the cost of potentially creating a lot more expando objects. We could also separately cache the native prototype on the holder, at the expense of having overlapping slots between the holder and expando objects.
At first glance, the latter approach is probably preferable, but I don't know how many expando objects and holder objects get instantiated in practice.
Flags: needinfo?(bobbyholley)
![]() |
Assignee | |
Comment 2•8 years ago
|
||
> At first glance, the latter approach is probably preferable
Yes, I agree. We'd still have annoying wrapping overhead on getPrototype from the expando object, since it's stored in the target compartment. But if one sets __proto__ on an Xray _and_ expects good performance, all I can offer is a nice padded room.
![]() |
Assignee | |
Comment 3•8 years ago
|
||
Oh, the obvious reason to cache on the holder, not the expando, is that then it's actually in the right compartment, so the nasty WrapObject overhead is not present.
Testcase, to be run in a chrome scratchpad targeting a non-e10s window:
(function() {
var node = content.document.documentElement;
var start = performance.now()
var count = 100000;
for (var i = 0; i < count; ++i) {
node.nextSibling;
}
var stop = performance.now();
alert(Math.round((stop - start)/count * 1e6));
})();
Without this bug fixed I see numbers in the 2800 range. With it fixed, I see numbers closer to 2100.
Without the IEFE, all the numbers are larger by 1000 or so. Presumably, writing, and maybe reading, global variables in the sandbox that scratchpad uses is horribly slow... :(
![]() |
Assignee | |
Comment 4•8 years ago
|
||
MozReview-Commit-ID: 5IRrE8EmL9A
Attachment #8850284 -
Flags: review?(bobbyholley)
![]() |
Assignee | |
Updated•8 years ago
|
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
![]() |
Assignee | |
Comment 5•8 years ago
|
||
MozReview-Commit-ID: ID9vMG3iJfZ
Attachment #8850285 -
Flags: review?(bobbyholley)
Comment 6•8 years ago
|
||
(In reply to Boris Zbarsky [:bz] (still a bit busy) (if a patch has no decent message, automatic r-) from comment #3)
> Without the IEFE, all the numbers are larger by 1000 or so. Presumably,
> writing, and maybe reading, global variables in the sandbox that scratchpad
> uses is horribly slow... :(
I suspect that has something to do with Scratchpad compiling the code to return a value. As I understand it, that disables most JIT optimizations at the top-level.
![]() |
Assignee | |
Comment 7•8 years ago
|
||
MozReview-Commit-ID: I78AoSB3TNW
Attachment #8850287 -
Flags: review?(bobbyholley)
Updated•8 years ago
|
Attachment #8850284 -
Flags: review?(bobbyholley) → review+
Updated•8 years ago
|
Attachment #8850285 -
Flags: review?(bobbyholley) → review+
Updated•8 years ago
|
Attachment #8850287 -
Flags: review?(bobbyholley) → review+
![]() |
Assignee | |
Comment 8•8 years ago
|
||
Try found a bug: the holders for OpaqueXrayTraits didn't have the slot, because I didn't find its createHolder method (it was in the header).
Fixed that by moving the new JSClass up to XrayTraits like so:
const JSClass XrayTraits::HolderClass = {
"XrayHolder", JSCLASS_HAS_RESERVED_SLOTS(HOLDER_SHARED_SLOT_COUNT)
};
and pushing to try again.
Pushed by bzbarsky@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/60471d1feaa4
part 1. Remove the unused reserved slots from the XPCWN xray holder. r=bholley
https://hg.mozilla.org/integration/mozilla-inbound/rev/3efe3c6f4e7f
part 2. Give all the Xray holders a JSClass that has a slot for caching a prototype. r=bholley
https://hg.mozilla.org/integration/mozilla-inbound/rev/8ba41a1bd062
part 3. Cache the proto of an Xray on its holder, so we don't have to keep re-wrapping it. r=bholley
Comment 10•8 years ago
|
||
backed this out in https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&revision=1e0598886d349e919fbe71ab3534574e13d40468&filter-classifiedState=unclassified&filter-resultStatus=testfailed&filter-resultStatus=busted&filter-resultStatus=exception because of bustage https://treeherder.mozilla.org/logviewer.html#?job_id=85840526&repo=mozilla-inbound
Flags: needinfo?(bzbarsky)
Comment 11•8 years ago
|
||
Backout by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/42b182f3367e
Backed out changeset 8ba41a1bd062
https://hg.mozilla.org/integration/mozilla-inbound/rev/2cf77bf80ba2
Backed out changeset 3efe3c6f4e7f
Comment 13•8 years ago
|
||
Pushed by bzbarsky@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/53b6c8e23941
part 1. Remove the unused reserved slots from the XPCWN xray holder. r=bholley
https://hg.mozilla.org/integration/mozilla-inbound/rev/81aa15f00924
part 2. Give all the Xray holders a JSClass that has a slot for caching a prototype. r=bholley
https://hg.mozilla.org/integration/mozilla-inbound/rev/26b0c85cce69
part 3. Cache the proto of an Xray on its holder, so we don't have to keep re-wrapping it. r=bholley
Comment 14•8 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/53b6c8e23941
https://hg.mozilla.org/mozilla-central/rev/81aa15f00924
https://hg.mozilla.org/mozilla-central/rev/26b0c85cce69
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in
before you can comment on or make changes to this bug.
Description
•