diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index fc03fb25bd06..e948dec5a4da 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -1683,7 +1683,7 @@ void nsJSContext::EnsureCCRunner(TimeDuration aDelay, TimeDuration aBudget) { CCRunnerFired, "EnsureCCRunner::CCRunnerFired", aDelay.ToMilliseconds(), aBudget.ToMilliseconds(), true, [] { return sShuttingDown; }); } else { - sCCRunner->SetBudget(aBudget.ToMilliseconds()); + sCCRunner->SetMinimumUsefulBudget(aBudget.ToMilliseconds()); nsIEventTarget* target = mozilla::GetCurrentEventTarget(); if (target) { sCCRunner->SetTimer(aDelay.ToMilliseconds(), target); diff --git a/xpcom/threads/IdleTaskRunner.cpp b/xpcom/threads/IdleTaskRunner.cpp index 404410bec867..792f1d9285ab 100644 --- a/xpcom/threads/IdleTaskRunner.cpp +++ b/xpcom/threads/IdleTaskRunner.cpp @@ -12,27 +12,28 @@ namespace mozilla { already_AddRefed IdleTaskRunner::Create( const CallbackType& aCallback, const char* aRunnableName, - uint32_t aMaxDelay, int64_t aNonIdleBudget, bool aRepeating, + uint32_t aMaxDelay, int64_t aMinimumUsefulBudget, bool aRepeating, const MayStopProcessingCallbackType& aMayStopProcessing) { if (aMayStopProcessing && aMayStopProcessing()) { return nullptr; } RefPtr runner = - new IdleTaskRunner(aCallback, aRunnableName, aMaxDelay, aNonIdleBudget, - aRepeating, aMayStopProcessing); + new IdleTaskRunner(aCallback, aRunnableName, aMaxDelay, + aMinimumUsefulBudget, aRepeating, aMayStopProcessing); runner->Schedule(false); // Initial scheduling shouldn't use idle dispatch. return runner.forget(); } IdleTaskRunner::IdleTaskRunner( const CallbackType& aCallback, const char* aRunnableName, - uint32_t aMaxDelay, int64_t aNonIdleBudget, bool aRepeating, + uint32_t aMaxDelay, int64_t aMinimumUsefulBudget, bool aRepeating, const MayStopProcessingCallbackType& aMayStopProcessing) : CancelableIdleRunnable(aRunnableName), mCallback(aCallback), mDelay(aMaxDelay), - mBudget(TimeDuration::FromMilliseconds(aNonIdleBudget)), + mMinimumUsefulBudget( + TimeDuration::FromMilliseconds(aMinimumUsefulBudget)), mRepeating(aRepeating), mTimerActive(false), mMayStopProcessing(aMayStopProcessing), @@ -49,7 +50,7 @@ IdleTaskRunner::Run() { bool deadLineWasNull = mDeadline.IsNull(); bool didRun = false; bool allowIdleDispatch = false; - if (deadLineWasNull || ((now + mBudget) < mDeadline)) { + if (deadLineWasNull || ((now + mMinimumUsefulBudget) < mDeadline)) { CancelTimer(); didRun = mCallback(mDeadline); // If we didn't do meaningful work, don't schedule using immediate @@ -78,8 +79,8 @@ void IdleTaskRunner::SetDeadline(mozilla::TimeStamp aDeadline) { mDeadline = aDeadline; } -void IdleTaskRunner::SetBudget(int64_t aBudget) { - mBudget = TimeDuration::FromMilliseconds(aBudget); +void IdleTaskRunner::SetMinimumUsefulBudget(int64_t aMinimumUsefulBudget) { + mMinimumUsefulBudget = TimeDuration::FromMilliseconds(aMinimumUsefulBudget); } void IdleTaskRunner::SetTimer(uint32_t aDelay, nsIEventTarget* aTarget) { diff --git a/xpcom/threads/IdleTaskRunner.h b/xpcom/threads/IdleTaskRunner.h index 93a55b3d7f4c..6d1af26b050d 100644 --- a/xpcom/threads/IdleTaskRunner.h +++ b/xpcom/threads/IdleTaskRunner.h @@ -29,13 +29,12 @@ class IdleTaskRunner final : public CancelableIdleRunnable { using MayStopProcessingCallbackType = std::function; public: - // An IdleTaskRunner will attempt to run in idle time, with a budget computed - // based on a (capped) estimate for how much idle time is available. If there - // is no idle time within `aMaxDelay` ms, it will fall back to running using - // a specified `aNonIdleBudget`. + // An IdleTaskRunner will attempt to run in any idle time period large enough + // to fit `aMinimumUsefulBudget`. If no such window occurs within `aMaxDelay` + // ms, it will stop waiting for idle time and run from a TYPE_ONE_SHOT timer. static already_AddRefed Create( const CallbackType& aCallback, const char* aRunnableName, - uint32_t aMaxDelay, int64_t aNonIdleBudget, bool aRepeating, + uint32_t aMaxDelay, int64_t aMinimumUsefulBudget, bool aRepeating, const MayStopProcessingCallbackType& aMayStopProcessing); NS_IMETHOD Run() override; @@ -46,9 +45,8 @@ class IdleTaskRunner final : public CancelableIdleRunnable { void SetTimer(uint32_t aDelay, nsIEventTarget* aTarget) override; - // Update the non-idle time budgeted for this callback. This really only - // makes sense for a repeating runner. - void SetBudget(int64_t aBudget); + // Update the minimum idle time that this callback would be invoked for. + void SetMinimumUsefulBudget(int64_t aMinimumUsefulBudget); nsresult Cancel() override; void Schedule(bool aAllowIdleDispatch); @@ -56,7 +54,7 @@ class IdleTaskRunner final : public CancelableIdleRunnable { private: explicit IdleTaskRunner( const CallbackType& aCallback, const char* aRunnableName, - uint32_t aMaxDelay, int64_t aNonIdleBudget, bool aRepeating, + uint32_t aMaxDelay, int64_t aMinimumUsefulBudget, bool aRepeating, const MayStopProcessingCallbackType& aMayStopProcessing); ~IdleTaskRunner(); void CancelTimer(); @@ -74,9 +72,8 @@ class IdleTaskRunner final : public CancelableIdleRunnable { // The null timestamp when the run is triggered by aMaxDelay instead of idle. TimeStamp mDeadline; - // The expected amount of time the callback will run for, when not running - // during idle time. - TimeDuration mBudget; + // The least duration worth calling the callback for during idle time. + TimeDuration mMinimumUsefulBudget; bool mRepeating; bool mTimerActive;