Closed Bug 1326105 Opened 7 years ago Closed 7 years ago

Don't capture an async stack for a callback that no one cares about

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla53
Tracking Status
firefox53 --- fixed

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

(Blocks 1 open bug)

Details

Attachments

(6 files, 2 obsolete files)

270 bytes, text/html
Details
1.33 KB, patch
smaug
: review+
Details | Diff | Splinter Review
4.71 KB, patch
smaug
: review+
Details | Diff | Splinter Review
2.99 KB, patch
smaug
: review+
Details | Diff | Splinter Review
5.32 KB, patch
smaug
: review+
Details | Diff | Splinter Review
9.87 KB, patch
smaug
: review+
Details | Diff | Splinter Review
When looking at the profiles for bug 1285874, I noticed a bunch of time taken capturing async stacks for removeEventListener calls.  This is happening because we create an EventListener callback object during the call, which captures the async stack.

The thing is, no one holds on to this EventListener, so there is no reason to care about its async stack.

We have an existing optimization to avoid calling HoldJSObjects() in this case; I'm going to expand it to skip capturing the async stack.
Attached file Performance testcase
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
Attachment #8822273 - Attachment is obsolete: true
Attachment #8822273 - Flags: review?(bugs)
Attachment #8822274 - Attachment is obsolete: true
Attachment #8822274 - Flags: review?(bugs)
Attachment #8822271 - Flags: review?(bugs) → review+
Comment on attachment 8822272 [details] [diff] [review]
part 3.  Move async stack capture out of the 'fast' CallbackObject constructor and into FinishSlowJSInitIfMoreThanOneOwner

I still wonder how useful async stack actually is.
Attachment #8822272 - Flags: review?(bugs) → review+
Attachment #8822334 - Flags: review?(bugs) → review+
Comment on attachment 8822270 [details] [diff] [review]
part 1.  dom::RootedCallback should hold on to a JSContext that it can then use in its destructor

Please add a comment why raw member variable is a safe thing, especially in a class which isn't explicitly marked to be stack-only.
Could we make RootedCallback MOZ_STACK_CLASS ? or even MOZ_RAII?
Though, looks like JS::Rooted is already MOZ_RAII. So I guess RootedCallback inherits that annotation, but it just isn't visible to the reader.
Attachment #8822270 - Flags: review?(bugs) → review+
Comment on attachment 8822339 [details] [diff] [review]
part 5.  Move the getting of the incumbent global to the finish-slow-js codepath too, since it's not needed if no one will ever call our callback

Does this end up helping with bug 1273481 some more?
Attachment #8822339 - Flags: review?(bugs) → review+
> Could we make RootedCallback MOZ_STACK_CLASS ? or even MOZ_RAII?

I added an explicit MOZ_RAII here.

> Does this end up helping with bug 1273481 some more?

Yes, it does.  Times on the microbenchmark there are like so, over here in a nightly clean profile (so with async stacks):

Current tip: ~1450
With parts 1-4: ~570
With parts 1-5: ~360

For comparison, Safari is at ~230 and Chrome at ~1100.
Pushed by bzbarsky@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/946d799f43af
part 1.  dom::RootedCallback should hold on to a JSContext that it can then use in its destructor.  r=smaug
https://hg.mozilla.org/integration/mozilla-inbound/rev/dd5b7e039015
part 2.  Rename CallbackObject::HoldJSObjectsIfMoreThanOneOwner to a more generic name and hand it a JSContext to use.  r=smaug
https://hg.mozilla.org/integration/mozilla-inbound/rev/56abaeb56804
part 3.  Move async stack capture out of the 'fast' CallbackObject constructor and into FinishSlowJSInitIfMoreThanOneOwner.  r=smaug
https://hg.mozilla.org/integration/mozilla-inbound/rev/413acc1afbd6
part 4.  Remove the now-unused JSContext argument of the protected CallbackObject constructor.  r=smaug
https://hg.mozilla.org/integration/mozilla-inbound/rev/9fdb9ee08a30
part 5.  Move the getting of the incumbent global to the finish-slow-js codepath too, since it's not needed if no one will ever call our callback.  r=smaug
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: