From 7392b9b504c985d5f28fa485a71c22ada6a0cf21 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Wed, 28 Jan 2026 18:02:20 +0200 Subject: [PATCH] Revert "Some fixes." This reverts commit 9a5010a8e35000418a29726f23973d28e92e27a6. --- dom/base/nsJSEnvironment.cpp | 61 ++++++++++++++++++++++++++++++---- dom/workers/RuntimeService.cpp | 4 +-- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index c6822ab9c5..8ece8028ef 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2222,9 +2222,12 @@ nsJSContext::MaybePokeCC() void nsJSContext::KillGCTimer() { - if (sGCTimer) { - sGCTimer->Cancel(); - NS_RELEASE(sGCTimer); + sScheduler->CancelScheduledTask(sMainThreadCollectorScheduling, + CollectorSchedule::eInitialGC); + sScheduler->CancelScheduledTask(sMainThreadCollectorScheduling, + CollectorSchedule::eGC); + sScheduler->CancelScheduledTask(sMainThreadCollectorScheduling, + CollectorSchedule::eVariableScheduledGC); } } @@ -2441,7 +2444,7 @@ nsJSContext::LikelyShortLivingObjectCreated() void mozilla::dom::StartupJSEnvironment() { - sScheduler = CycleCollectedJSContext::GetScheduler(); + sScheduler = CycleCollectedJSRuntime::GetScheduler(); MOZ_ASSERT(sScheduler); MOZ_ASSERT(sMainThreadCollectorScheduling[CollectorSchedule::eGC].mDelayMillis == NS_GC_DELAY); @@ -2771,9 +2774,9 @@ nsJSContext::EnsureStatics() "javascript.options.compact_on_user_inactive", true); - Preferences::AddUintVarCache(&sCompactOnUserInactiveDelay, - "javascript.options.compact_on_user_inactive_delay", - NS_DEAULT_INACTIVE_GC_DELAY); + sMainThreadCollectorScheduling[CollectorSchedule::eShrinkGCBuffers].mDelayMillis = + Preferences::GetUint("javascript.options.compact_on_user_inactive_delay", + NS_DEFAULT_INACTIVE_GC_DELAY); Preferences::AddBoolVarCache(&sPostGCEventsToConsole, JS_OPTIONS_DOT_STR "mem.log"); @@ -2790,6 +2793,50 @@ nsJSContext::EnsureStatics() sIsInitialized = true; } +void +nsJSContext::NotifyDidPaint() +{ + sDidPaintAfterPreviousICCSlice = true; + if (sICCTimer) { + static uint32_t sCount = 0; + // 16 here is the common value for refresh driver tick frequency. + static const uint32_t kTicksPerSliceDelay = kICCIntersliceDelay / 16; + if (++sCount % kTicksPerSliceDelay != 0) { + // Don't trigger CC slice all the time after paint, but often still. + // The key point is to trigger it right after paint, especially when + // we're running RefreshDriver constantly. + return; + } + + sICCTimer->Cancel(); + ICCTimerFired(nullptr, nullptr); + if (sICCTimer) { + sICCTimer->InitWithNamedFuncCallback(ICCTimerFired, nullptr, + kICCIntersliceDelay, + nsITimer::TYPE_REPEATING_SLACK, + "ICCTimerFired"); + } + } else if (sCCTimer) { + static uint32_t sCount = 0; + static const uint32_t kTicksPerForgetSkippableDelay = + NS_CC_SKIPPABLE_DELAY / 16; + if (++sCount % kTicksPerForgetSkippableDelay != 0) { + // The comment above about triggering CC slice applies to forget skippable + // too. + return; + } + + sCCTimer->Cancel(); + CCTimerFired(nullptr, nullptr); + if (sCCTimer) { + sCCTimer->InitWithNamedFuncCallback(CCTimerFired, nullptr, + NS_CC_SKIPPABLE_DELAY, + nsITimer::TYPE_REPEATING_SLACK, + "CCTimerFired"); + } + } +} + nsScriptNameSpaceManager* mozilla::dom::GetNameSpaceManager() { diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 93928db5d4..bfdbba58ea 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -1107,9 +1107,9 @@ public: uint32_t aDelay) override { NS_ENSURE_STATE(mWorkerPrivate); - RefPtr wrapper = + nsRefPtr wrapper = new ExternalRunnableWrapper(mWorkerPrivate, aRunnable); - RefPtr target = + nsRefPtr target = new TimerThreadEventTarget(mWorkerPrivate, wrapper); aTimer->SetTarget(target); return aTimer->InitWithFuncCallback(DummyCallback, nullptr, aDelay,