Delete `removeObserver()` calls for `xpcom-shutdown` observers from within observe()
Categories
(Core :: XPCOM, enhancement, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox66 | --- | affected |
People
(Reporter: Gijs, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
| Reporter | ||
Comment 2•7 years ago
|
||
Comment 3•7 years ago
|
||
| Reporter | ||
Comment 4•7 years ago
|
||
Comment 5•6 years ago
|
||
Let's park this in P3 until Gijs gets a chance to come back with perf numbers.
Updated•6 years ago
|
| Reporter | ||
Comment 6•6 years ago
|
||
This is a bug in consumers, not xpcom itself.
| Reporter | ||
Comment 7•5 years ago
|
||
So I finally picked this back up. I fiddled around with clang this morning and came up with a rudimentary check that logs warnings when calling RemoveObserver(..., "xpcom-shutdown") directly from within Observe(), and pushed to try. clang is somehow upset on all the debug builds because of some assertion, but the opt builds completed successfully and logged 20 warnings. As far as I can tell from a very quick look, they are all correct (ie no false positives), despite the checker not being failsafe (e.g. if you had registered for multiple observer notificiations, you could conceivably remove the shutdown observer when you get one of the other notifications). Full list is at the bottom of this comment.
Now, the trivial thing to do is to just remove all the spurious calls here. However, having looked at all of these, I've spotted a few patterns where maybe we can avoid having things observe shutdown at all.
- removing all the other observers
- updating a class member
mIsShutdownbool - cancelling timers
- joining threads / shutting down subprocesses
A bunch of these feel like they could be handled more gracefully and/or might also be unnecessary. Doug, in your investigations so far, do you have a rough idea how much time we spend handling xpcom-shutdown as a proportion of shutdown, and if it's worth coming up with better abstractions for some of this?
List:
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/xpcom/threads/nsProcessCommon.cpp#530
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/netwerk/cookie/CookieServiceChild.cpp#591
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/netwerk/base/NetworkConnectivityService.cpp#167
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/netwerk/base/nsProtocolProxyService.cpp#917
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/netwerk/protocol/http/DelayHttpChannelQueue.cpp#90
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp#76
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/base/nsCCUncollectableMarker.cpp#299
https://firefoxci.taskcluster-artifacts.net/bbXA4iW3QduxZeIqvL1ywg/0/public/logs/live_backing.log
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/file/ipc/IPCBlobInputStreamStorage.cpp#60
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/geolocation/Geolocation.cpp#578
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/media/mediacontrol/MediaControlService.cpp#85
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/storage/StorageActivityService.cpp#181
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/storage/StorageIPC.cpp#401
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/ipc/ProcessHangMonitor.cpp#1252
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/workers/remoteworkers/RemoteWorkerService.cpp#162
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/dom/reporting/ReportDeliver.cpp#381
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/layout/xul/nsXULPopupManager.cpp#173
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/security/manager/ssl/nsNSSComponent.cpp#1308
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/toolkit/components/finalizationwitness/FinalizationWitnessService.cpp#216
https://searchfox.org/mozilla-central/rev/0439db3a39faddb90197a87cc184c57dcbf0a770/toolkit/components/antitracking/AntiTrackingCommon.cpp#710,747
| Reporter | ||
Comment 8•5 years ago
|
||
Comment 9•5 years ago
|
||
(In reply to :Gijs (he/him) from comment #7)
A bunch of these feel like they could be handled more gracefully and/or might also be unnecessary. Doug, in your investigations so far, do you have a rough idea how much time we spend handling
xpcom-shutdownas a proportion of shutdown, and if it's worth coming up with better abstractions for some of this?
I'm not the most confident about my intuitions here, unfortunately. Bug 1613733 yielded substantial wins at both the 5th and 95th percentiles, and that does not match numbers which you would expect from shutdown profiling on reference hardware. In any case bug 1613733 saw these wins without removing any shutdown IO, so there's a solid case to be made for simply avoiding unnecessary freeing and cleanup on the CPU. xpcom-shutdown does certainly show up in profiles, so work to improve it will not be entirely wasted, but it's hard to say precisely how much we might expect from it.
Updated•3 years ago
|
Comment 10•1 year ago
|
||
Moving this to XPCOM for further discussion. I am not sure I understand the intention, it seems we want to just avoid the removal of the observers during shutdown? That seems to not be the most impactful thing to me. Do we still think this is gaining us something?
| Reporter | ||
Comment 11•1 year ago
|
||
(In reply to Jens Stutte [:jstutte] from comment #10)
Moving this to XPCOM for further discussion. I am not sure I understand the intention, it seems we want to just avoid the removal of the observers during shutdown? That seems to not be the most impactful thing to me. Do we still think this is gaining us something?
Well, we used to have a substantial number of shutdown crashes because shutdown was too slow. And as I noted in the blocking bug 1348886, we still have way too many xpcom-shutdown observers.
When I filed this I was hoping that if we could automatically remove calls to RemoveObserver for xpcom-shutdown being called inside Observe, and then remove any cases where the relevant block was empty, that would help cut down on the number of xpcom-shutdown observers (ie maybe this could be the "easy" first bit of trying to get that number under control). I don't know if that's still the case.
Description
•