Bug 1856545 - Try to utilize idle time more, r=farre

We can go through quite a few more timers these days, since timers are stored now in an array and iterating through that is fast.
Also, relying on timer value for another thread or low priority timers does prevent idle tasks to run in some cases, and now that more timers
are iterated through, that behavior can be tweaked.

For RefreshDriver this is taking the simple approach and just let idle tasks to run if RefreshDriver isn't ticking. We do start RefreshDriverTimer pretty
much always when something in DOM or layout is changing.

Differential Revision: https://phabricator.services.mozilla.com/D189909
This commit is contained in:
Olli Pettay 2023-10-06 11:04:04 +00:00
Родитель fed4a076d6
Коммит 455b5d83ea
4 изменённых файлов: 16 добавлений и 8 удалений

Просмотреть файл

@ -223,6 +223,10 @@ class RefreshDriverTimer {
TimeStamp GetIdleDeadlineHint(TimeStamp aDefault) {
MOZ_ASSERT(NS_IsMainThread());
if (!IsTicking() && !gfxPlatform::IsInLayoutAsapMode()) {
return aDefault;
}
TimeStamp mostRecentRefresh = MostRecentRefresh();
TimeDuration refreshPeriod = GetTimerRate();
TimeStamp idleEnd = mostRecentRefresh + refreshPeriod;

Просмотреть файл

@ -345,8 +345,12 @@ class FindExpirationTimeState final {
} while (true);
mBefore = TimeStamp::Now();
mMiddle = mBefore + TimeDuration::FromMilliseconds(
kTimerOffset + kTimerInterval * kNumTimers / 2);
// To avoid getting exactly the same time for a timer and mMiddle, subtract
// 50 ms.
mMiddle = mBefore +
TimeDuration::FromMilliseconds(kTimerOffset +
kTimerInterval * kNumTimers / 2) -
TimeDuration::FromMilliseconds(50);
for (uint32_t i = 0; i < kNumTimers; ++i) {
nsCOMPtr<nsITimer> timer = NS_NewTimer();
ASSERT_TRUE(timer);

Просмотреть файл

@ -25,7 +25,7 @@ static const double kLongIdlePeriodMS = 50.0;
// or during page load
// now + idle_period.during_page_load.min + layout.idle_period.time_limit
static const uint32_t kMaxTimerThreadBound = 5; // milliseconds
static const uint32_t kMaxTimerThreadBound = 25; // Number of timers to check.
namespace mozilla {

Просмотреть файл

@ -1064,11 +1064,11 @@ TimeStamp TimerThread::FindNextFireTimeForCurrentThread(TimeStamp aDefault,
}
if (aSearchBound == 0) {
// Return the currently highest timeout when we reach the bound.
// This won't give accurate information if we stop before finding
// any timer for the current thread, but at least won't report too
// long idle period.
return timer->mTimeout;
// Couldn't find any non-low priority timers for the current thread.
// Return a compromise between a very short and a long idle time.
TimeStamp fallbackDeadline =
TimeStamp::Now() + TimeDuration::FromMilliseconds(16);
return fallbackDeadline < aDefault ? fallbackDeadline : aDefault;
}
--aSearchBound;