Bug 685516: Instead of decoding small images synchronously and large images asynchronously, always decode synchronously for some time, and post the remainder to the event loop if necessary. r=joe
authorKyle Huey <khuey@kylehuey.com>
Mon, 10 Oct 2011 12:18:52 -0400
changeset 78464 367ff8c94636
parent 78463 2c1efd925484
child 78465 f2c16b13cf65
push id21300
push userkhuey@mozilla.com
push date2011-10-10 16:19 +0000
treeherdermozilla-central@d3b8c0394c5e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs685516
milestone10.0a1
Bug 685516: Instead of decoding small images synchronously and large images asynchronously, always decode synchronously for some time, and post the remainder to the event loop if necessary. r=joe
modules/libpr0n/src/RasterImage.cpp
modules/libpr0n/src/imgRequest.cpp
modules/libpref/src/init/all.js
--- a/modules/libpr0n/src/RasterImage.cpp
+++ b/modules/libpr0n/src/RasterImage.cpp
@@ -80,33 +80,27 @@ using namespace mozilla::imagelib;
 static PRLogModuleInfo *gCompressedImageAccountingLog = PR_NewLogModule ("CompressedImageAccounting");
 #else
 #define gCompressedImageAccountingLog
 #endif
 
 // Tweakable progressive decoding parameters
 static PRUint32 gDecodeBytesAtATime = 200000;
 static PRUint32 gMaxMSBeforeYield = 400;
-static PRUint32 gMaxBytesForSyncDecode = 150000;
 
 void
 RasterImage::SetDecodeBytesAtATime(PRUint32 aBytesAtATime)
 {
   gDecodeBytesAtATime = aBytesAtATime;
 }
 void
 RasterImage::SetMaxMSBeforeYield(PRUint32 aMaxMS)
 {
   gMaxMSBeforeYield = aMaxMS;
 }
-void
-RasterImage::SetMaxBytesForSyncDecode(PRUint32 aMaxBytes)
-{
-  gMaxBytesForSyncDecode = aMaxBytes;
-}
 
 /* We define our own error checking macros here for 2 reasons:
  *
  * 1) Most of the failures we encounter here will (hopefully) be
  * the result of decoding failures (ie, bad data) and not code
  * failures. As such, we don't want to clutter up debug consoles
  * with spurious messages about NS_ENSURE_SUCCESS failures.
  *
@@ -2381,23 +2375,22 @@ RasterImage::RequestDecode()
   // If we already have a pending worker, we're done
   if (mWorkerPending)
     return NS_OK;
 
   // If we've read all the data we have, we're done
   if (mBytesDecoded == mSourceData.Length())
     return NS_OK;
 
-  // If it's a smallish image, it's not worth it to do things async
-  if (!mDecoded && !mInDecoder && mHasSourceData && (mSourceData.Length() < gMaxBytesForSyncDecode))
-    return SyncDecode();
-
-  // If we get this far, dispatch the worker. We do this instead of starting
-  // any immediate decoding to guarantee that all our decode notifications are
-  // dispatched asynchronously, and to ensure we stay responsive.
+  // If we can do decoding now, do so.  Small images will decode completely,
+  // large images will decode a bit and post themselves to the event loop
+  // to finish decoding.
+  if (!mDecoded && !mInDecoder && mHasSourceData)
+    return mWorker->Run();
+
   return mWorker->Dispatch();
 }
 
 // Synchronously decodes as much data as possible
 nsresult
 RasterImage::SyncDecode()
 {
   nsresult rv;
--- a/modules/libpr0n/src/imgRequest.cpp
+++ b/modules/libpr0n/src/imgRequest.cpp
@@ -83,17 +83,16 @@
 
 #include "DiscardTracker.h"
 #include "nsAsyncRedirectVerifyHelper.h"
 
 #define DISCARD_PREF "image.mem.discardable"
 #define DECODEONDRAW_PREF "image.mem.decodeondraw"
 #define BYTESATATIME_PREF "image.mem.decode_bytes_at_a_time"
 #define MAXMS_PREF "image.mem.max_ms_before_yield"
-#define MAXBYTESFORSYNC_PREF "image.mem.max_bytes_for_sync_decode"
 #define SVG_MIMETYPE "image/svg+xml"
 
 using namespace mozilla;
 using namespace mozilla::imagelib;
 
 /* Kept up to date by a pref observer. */
 static bool gDecodeOnDraw = false;
 static bool gDiscardable = false;
@@ -127,21 +126,16 @@ ReloadPrefs()
   if (NS_SUCCEEDED(Preferences::GetInt(BYTESATATIME_PREF, &bytesAtATime))) {
     RasterImage::SetDecodeBytesAtATime(bytesAtATime);
   }
 
   if (NS_SUCCEEDED(Preferences::GetInt(MAXMS_PREF, &maxMS))) {
     RasterImage::SetMaxMSBeforeYield(maxMS);
   }
 
-  if (NS_SUCCEEDED(Preferences::GetInt(MAXBYTESFORSYNC_PREF,
-                                       &maxBytesForSync))) {
-    RasterImage::SetMaxBytesForSyncDecode(maxBytesForSync);
-  }
-
   // Discard timeout
   mozilla::imagelib::DiscardTracker::ReloadTimeout();
 }
 
 // Observer
 class imgRequestPrefObserver : public nsIObserver {
 public:
     NS_DECL_ISUPPORTS
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -3271,19 +3271,16 @@ pref("image.mem.decodeondraw", true);
 pref("image.mem.min_discard_timeout_ms", 10000);
 
 // Chunk size for calls to the image decoders
 pref("image.mem.decode_bytes_at_a_time", 4096);
 
 // The longest time we can spend in an iteration of an async decode
 pref("image.mem.max_ms_before_yield", 5);
 
-// The maximum source data size for which we auto sync decode
-pref("image.mem.max_bytes_for_sync_decode", 150000);
-
 // WebGL prefs
 pref("webgl.force-enabled", false);
 pref("webgl.disabled", false);
 pref("webgl.shader_validator", true);
 pref("webgl.force_osmesa", false);
 pref("webgl.osmesalib", "");
 pref("webgl.verbose", false);
 pref("webgl.prefer-native-gl", false);