From a42777ee145c654753d81f034cb34765cceead55 Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Fri, 8 Nov 2019 21:07:52 +0000 Subject: [PATCH] Bug 1594015: Ensure that threads with odd ProcessNextEvent loops get correct event delays r=froydnj Socket Thread and Worker Threads use custom event loops and don't wait in calls to ProcessNextEvent all the time; this can lead to odd Responsiveness numbers. Differential Revision: https://phabricator.services.mozilla.com/D51835 --HG-- extra : moz-landing-system : lando --- dom/workers/WorkerPrivate.cpp | 6 ++++++ netwerk/base/nsSocketTransportService2.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 43c622cb6b9d..29a2da5907c9 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -2764,6 +2764,12 @@ void WorkerPrivate::DoRunLoop(JSContext* aCx) { !(debuggerRunnablesPending = !mDebuggerQueue.IsEmpty()) && !(normalRunnablesPending = NS_HasPendingEvents(mThread)) && !(mStatus != Running && !HasActiveWorkerRefs())) { + // We pop out to this loop when there are no pending events. + // If we don't reset these, we may not re-enter ProcessNextEvent() + // until we have events to process, and it may seem like we have + // an event running for a very long time. + mThread->SetRunningEventDelay(TimeDuration(), TimeStamp()); + WaitForWorkerEvents(); } diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 6160cd0b7988..f2b155b22350 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -961,6 +961,11 @@ nsSocketTransportService::Run() { startOfNextIteration = TimeStamp::NowLoRes(); } pollDuration = nullptr; + // We pop out to this loop when there are no pending events. + // If we don't reset these, we may not re-enter ProcessNextEvent() + // until we have events to process, and it may seem like we have + // an event running for a very long time. + mRawThread->SetRunningEventDelay(TimeDuration(), TimeStamp()); do { if (Telemetry::CanRecordPrereleaseData()) {