Bug 1335148 - Part 1: Dynamically determine content viewer count on Android, too. r?snorp,bz draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 29 Mar 2018 21:51:13 +0200
changeset 793277 21e61d8cef8108bdf41dff3cd3586255d6545e06
parent 793270 e55b288ca2dae63239b06d7d27599328711008a0
child 793278 2147d58661f98c49b905d032975c0422ed8cffc1
push id109332
push usermozilla@buttercookie.de
push dateWed, 09 May 2018 19:48:41 +0000
reviewerssnorp, bz
bugs1335148
milestone62.0a1
Bug 1335148 - Part 1: Dynamically determine content viewer count on Android, too. r?snorp,bz The current limit of at most one bfcache entry on Android dates back to when Fennec was built for the Nokia N810, which had a whopping 128 MB of memory. Since a few years have passed since then and mobile device technology has evolved considerably, it should be safe now to allow a little more than that. Since web sites sizes might have grown somewhat as well compared to the figure of 4MB mentioned in CalcMaxTotalViweres(), though and to be absolutely on the safe side, we still tweak the formula when building for Android, though. If in the worst case even those assumptions turn out too generous, we will still be protected by the fact that - we temporarily disable the bfcache when the OS signals memory pressure, and - our contentViewerTimeout is set to a lower value than on Desktop, so bfcache entries will expire sooner MozReview-Commit-ID: 1A6d0Q6Mdx0
docshell/shistory/nsSHistory.cpp
mobile/android/app/mobile.js
--- a/docshell/shistory/nsSHistory.cpp
+++ b/docshell/shistory/nsSHistory.cpp
@@ -255,33 +255,43 @@ NS_INTERFACE_MAP_BEGIN(nsSHistory)
   NS_INTERFACE_MAP_ENTRY(nsISHistoryInternal)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END
 
 // static
 uint32_t
 nsSHistory::CalcMaxTotalViewers()
 {
+  // This value allows tweaking how fast the allowed amount of content viewers
+  // grows with increasing amounts of memory. Larger values mean slower growth.
+  #ifdef ANDROID
+  #define MAX_TOTAL_VIEWERS_BIAS 15.9
+  #else
+  #define MAX_TOTAL_VIEWERS_BIAS 14
+  #endif
+
   // Calculate an estimate of how many ContentViewers we should cache based
   // on RAM.  This assumes that the average ContentViewer is 4MB (conservative)
   // and caps the max at 8 ContentViewers
   //
   // TODO: Should we split the cache memory betw. ContentViewer caching and
   // nsCacheService?
   //
-  // RAM      ContentViewers
-  // -----------------------
-  // 32   Mb       0
-  // 64   Mb       1
-  // 128  Mb       2
-  // 256  Mb       3
-  // 512  Mb       5
-  // 1024 Mb       8
-  // 2048 Mb       8
-  // 4096 Mb       8
+  // RAM    | ContentViewers | on Android
+  // -------------------------------------
+  // 32   Mb       0                0
+  // 64   Mb       1                0
+  // 128  Mb       2                0
+  // 256  Mb       3                1
+  // 512  Mb       5                2
+  // 768  Mb       6                2
+  // 1024 Mb       8                3
+  // 2048 Mb       8                5
+  // 3072 Mb       8                7
+  // 4096 Mb       8                8
   uint64_t bytes = PR_GetPhysicalMemorySize();
 
   if (bytes == 0) {
     return 0;
   }
 
   // Conversion from unsigned int64_t to double doesn't work on all platforms.
   // We need to truncate the value at INT64_MAX to make sure we don't
@@ -291,17 +301,17 @@ nsSHistory::CalcMaxTotalViewers()
   }
 
   double kBytesD = (double)(bytes >> 10);
 
   // This is essentially the same calculation as for nsCacheService,
   // except that we divide the final memory calculation by 4, since
   // we assume each ContentViewer takes on average 4MB
   uint32_t viewers = 0;
-  double x = std::log(kBytesD) / std::log(2.0) - 14;
+  double x = std::log(kBytesD) / std::log(2.0) - MAX_TOTAL_VIEWERS_BIAS;
   if (x > 0) {
     viewers = (uint32_t)(x * x - x + 2.001); // add .001 for rounding
     viewers /= 4;
   }
 
   // Cap it off at 8 max
   if (viewers > 8) {
     viewers = 8;
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -121,17 +121,17 @@ pref("network.predictor.preserve", 50); 
 
 // Use JS mDNS as a fallback
 pref("network.mdns.use_js_fallback", false);
 
 /* How many times should have passed before the remote tabs list is refreshed */
 pref("browser.display.remotetabs.timeout", 10);
 
 /* session history */
-pref("browser.sessionhistory.max_total_viewers", 1);
+pref("browser.sessionhistory.max_total_viewers", -1);
 pref("browser.sessionhistory.max_entries", 50);
 pref("browser.sessionhistory.contentViewerTimeout", 360);
 pref("browser.sessionhistory.bfcacheIgnoreMemoryPressure", false);
 
 /* session store */
 pref("browser.sessionstore.resume_from_crash", true);
 pref("browser.sessionstore.interval", 10000); // milliseconds
 pref("browser.sessionstore.backupInterval", 120000); // milliseconds -> 2 minutes