commit e1df4d5c51b83a64ba0c7008f3d0673255c0e7ac
parent 3d3134616d7c8cadaf921971973a387a1b9d7a33
Author: Artur Iunusov <aiunusov@mozilla.com>
Date: Mon, 1 Dec 2025 09:57:52 +0000
Bug 2002517 - FIX Extension native messaging performance, r=smaug,extension-reviewers,robwu
- added a chrome worker exception
Differential Revision: https://phabricator.services.mozilla.com/D274356
Diffstat:
5 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/dom/base/TimeoutManager.cpp b/dom/base/TimeoutManager.cpp
@@ -98,7 +98,7 @@ bool TimeoutManager::IsBackground() const {
bool TimeoutManager::IsActive() const {
// A window/worker is considered active if:
- // * It is a chrome window
+ // * It is a chrome window/worker
// * It is playing audio
//
// Note that a window/worker can be considered active if it is either in the
@@ -109,6 +109,10 @@ bool TimeoutManager::IsActive() const {
return true;
}
+ if (mIsChromeWorker) {
+ return true;
+ }
+
// Check if we're playing audio
if (mGlobalObject.IsPlayingAudio()) {
return true;
@@ -326,7 +330,8 @@ TimeDuration TimeoutManager::CalculateDelay(Timeout* aTimeout) const {
TimeDuration result = aTimeout->mInterval;
if (aTimeout->mNestingLevel >=
- StaticPrefs::dom_clamp_timeout_nesting_level()) {
+ StaticPrefs::dom_clamp_timeout_nesting_level() &&
+ !mIsChromeWorker) {
uint32_t minTimeoutValue = StaticPrefs::dom_min_timeout_value();
result = TimeDuration::Max(result,
TimeDuration::FromMilliseconds(minTimeoutValue));
@@ -408,7 +413,8 @@ uint32_t TimeoutManager::sNestingLevel = 0;
TimeoutManager::TimeoutManager(nsIGlobalObject& aHandle,
uint32_t aMaxIdleDeferMS,
- nsISerialEventTarget* aEventTarget)
+ nsISerialEventTarget* aEventTarget,
+ bool aIsChromeWorker)
: mGlobalObject(aHandle),
mExecutor(new TimeoutExecutor(this, false, 0)),
mIdleExecutor(new TimeoutExecutor(this, true, aMaxIdleDeferMS)),
@@ -429,7 +435,8 @@ TimeoutManager::TimeoutManager(nsIGlobalObject& aHandle,
mBudgetThrottleTimeouts(false),
mIsLoading(false),
mEventTarget(aEventTarget),
- mIsWindow(aHandle.GetAsInnerWindow()) {
+ mIsWindow(aHandle.GetAsInnerWindow()),
+ mIsChromeWorker(aIsChromeWorker) {
MOZ_LOG(gTimeoutLog, LogLevel::Debug,
("TimeoutManager %p created, tracking bucketing %s\n", this,
StaticPrefs::privacy_trackingprotection_annotate_channels()
diff --git a/dom/base/TimeoutManager.h b/dom/base/TimeoutManager.h
@@ -30,7 +30,8 @@ class TimeoutManager final {
public:
TimeoutManager(nsIGlobalObject& aHandle, uint32_t aMaxIdleDeferMS,
- nsISerialEventTarget* aEventTarget);
+ nsISerialEventTarget* aEventTarget,
+ bool aIsChromeWorker = false);
~TimeoutManager();
TimeoutManager(const TimeoutManager& rhs) = delete;
void operator=(const TimeoutManager& rhs) = delete;
@@ -268,6 +269,8 @@ class TimeoutManager final {
const bool mIsWindow;
+ const bool mIsChromeWorker;
+
uint32_t mNestingLevel{0};
static uint32_t sNestingLevel;
diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp
@@ -270,7 +270,8 @@ WorkerGlobalScopeBase::WorkerGlobalScopeBase(
mClientSource(std::move(aClientSource)),
mSerialEventTarget(aWorkerPrivate->HybridEventTarget()) {
mTimeoutManager = MakeUnique<dom::TimeoutManager>(
- *this, /* not used on workers */ 0, mSerialEventTarget);
+ *this, /* not used on workers */ 0, mSerialEventTarget,
+ mWorkerPrivate->IsChromeWorker());
LOG(("WorkerGlobalScopeBase::WorkerGlobalScopeBase [%p]", this));
MOZ_ASSERT(mWorkerPrivate);
#ifdef DEBUG
diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js b/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js
@@ -10,7 +10,7 @@
// on slow, resource-constrained devices. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=1951522#c31
-let max_round_trip_time_ms = 90;
+let max_round_trip_time_ms = 30;
const MAX_ROUND_TRIP_TIME_MS = max_round_trip_time_ms;
diff --git a/toolkit/modules/subprocess/test/xpcshell/test_subprocess_perf.js b/toolkit/modules/subprocess/test/xpcshell/test_subprocess_perf.js
@@ -9,7 +9,7 @@
// https://bugzilla.mozilla.org/show_bug.cgi?id=1729546#c4 and
// https://bugzilla.mozilla.org/show_bug.cgi?id=1951522#c31
-let max_round_trip_time_ms = 90;
+let max_round_trip_time_ms = 30;
const MAX_ROUND_TRIP_TIME_MS = max_round_trip_time_ms;