commit f450fe1ecfd2086fdd5333a805fcaf946ba4720b
parent 5525fb5db4da63cc0aeed63bb93a373e12cfa146
Author: acreskeyMoz <acreskey@mozilla.com>
Date: Mon, 10 Nov 2025 16:23:18 +0000
Bug 1946429 - Disable RCWN (Race Cache With Network) for devices with SSDs r=jesup,necko-reviewers,valentin
To minimize unnecessary network requests, we are by default disabing RCWN unless the client explicitly has a non-ssd drive (API only exists on Windows).
Experiments show that this is a likely net benefit to navigation performance and it definitively reduces client and infrastrucure energy expenditures.
Differential Revision: https://phabricator.services.mozilla.com/D261021
Diffstat:
2 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
@@ -13412,14 +13412,17 @@
value: false
mirror: always
-# If we should attempt to race the cache and network.
+# If we should attempt to race the cache with network.
+# See also race_with_non_ssd for auto-enable behavior on Windows non-SSD drives.
- name: network.http.rcwn.enabled
type: bool
-#if defined(ANDROID)
value: false
-#else
+ mirror: always
+
+# If we should attempt to race the cache with network for non-SSD drives (Windows only).
+- name: network.http.rcwn.race_with_non_ssd
+ type: bool
value: true
-#endif
mirror: always
- name: network.http.rcwn.cache_queue_normal_threshold
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -104,6 +104,9 @@
#include "mozilla/dom/ReferrerInfo.h"
#include "mozilla/glean/DomSecurityMetrics.h"
#include "mozilla/Telemetry.h"
+#include "mozilla/Services.h"
+#include "nsISystemInfo.h"
+#include "mozilla/Components.h"
#include "AlternateServices.h"
#include "NetworkMarker.h"
#include "nsIDNSRecord.h"
@@ -4637,6 +4640,41 @@ nsresult nsHttpChannel::OpenCacheEntry(bool isHttps) {
return OpenCacheEntryInternal(isHttps);
}
+#ifdef XP_WIN
+static mozilla::Maybe<bool> sHasSSD;
+#endif
+
+static bool RCWNEnabled() {
+ // State table for RCWN logic (race_with_non_ssd is Windows only):
+ // network.http.rcwn.enabled | Device | race_with_non_ssd | Result
+ // true | any | any | Enabled
+ // false | SSD | any | Disabled
+ // false | non-SSD | true | Enabled
+ // false | non-SSD | false | Disabled
+
+ bool rcwnEnabled = StaticPrefs::network_http_rcwn_enabled();
+#ifdef XP_WIN
+ if (!rcwnEnabled) {
+ if (sHasSSD.isNothing()) {
+ bool hasSSD = true;
+ nsCOMPtr<nsIPropertyBag2> sysInfo =
+ mozilla::components::SystemInfo::Service();
+ if (NS_SUCCEEDED(sysInfo->GetPropertyAsBool(u"hasSSD"_ns, &hasSSD))) {
+ sHasSSD = Some(hasSSD);
+ } else {
+ // Failed to detect, assume SSD (conservative default)
+ sHasSSD = Some(true);
+ }
+ }
+ if (sHasSSD.isSome() && !sHasSSD.value()) {
+ // For non-SSD devices, check the non-SSD-specific preference
+ rcwnEnabled = StaticPrefs::network_http_rcwn_race_with_non_ssd();
+ }
+ }
+#endif
+ return rcwnEnabled;
+}
+
nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) {
nsresult rv;
@@ -4771,8 +4809,7 @@ nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) {
maybeRCWN = false;
}
- if ((mNetworkTriggerDelay || StaticPrefs::network_http_rcwn_enabled()) &&
- maybeRCWN && mAllowRCWN) {
+ if ((mNetworkTriggerDelay || RCWNEnabled()) && maybeRCWN && mAllowRCWN) {
bool hasAltData = false;
uint32_t sizeInKb = 0;
rv = cacheStorage->GetCacheIndexEntryAttrs(
@@ -4790,7 +4827,7 @@ nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) {
if (!mCacheOpenDelay) {
MOZ_ASSERT(NS_IsMainThread(), "Should be called on the main thread");
if (mNetworkTriggered) {
- mRaceCacheWithNetwork = StaticPrefs::network_http_rcwn_enabled();
+ mRaceCacheWithNetwork = RCWNEnabled();
}
rv = cacheStorage->AsyncOpenURI(mCacheEntryURI, mCacheIdExtension,
cacheEntryOpenFlags, this);