Bug 411579 - "Optimize read file buffer sizes for faster startup times" [p=jmathies@mozilla.com (Jim Mathies) r=sayrer sr=bsmedberg a=blocking1.9+]
authorreed@reedloden.com
Fri, 18 Jan 2008 01:08:09 -0800
changeset 10386 e658c03654d10fca4068bfed31159633b79430b9
parent 10385 6afb19fdb7b91002385e53b2dbb749deae381777
child 10387 f2bb82f234f9b96e60b3e212c3aa812fae80a7e2
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssayrer, bsmedberg, blocking1.9
bugs411579
milestone1.9b3pre
Bug 411579 - "Optimize read file buffer sizes for faster startup times" [p=jmathies@mozilla.com (Jim Mathies) r=sayrer sr=bsmedberg a=blocking1.9+]
js/src/xpconnect/loader/mozJSComponentLoader.cpp
modules/libpref/src/nsPrefService.cpp
xpcom/io/nsFastLoadFile.cpp
--- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ -90,23 +90,23 @@ static const char kObserverServiceContra
 /* Some platforms don't have an implementation of PR_MemMap(). */
 /* See bug 318077 for WinCE.                                   */
 #if !defined(XP_BEOS) && !defined(XP_OS2) && !defined(WINCE)
 #define HAVE_PR_MEMMAP
 #endif
 
 /**
  * Buffer sizes for serialization and deserialization of scripts.
- * These should be tuned at some point.
+ * FIXME: bug #411579 (tune this macro!) Last updated: Jan 2008
  */
 #define XPC_SERIALIZATION_BUFFER_SIZE   (64 * 1024)
-#define XPC_DESERIALIZATION_BUFFER_SIZE (8 * 1024)
+#define XPC_DESERIALIZATION_BUFFER_SIZE (12 * 8192)
 
 // Inactivity delay before closing our fastload file stream.
-static const int kFastLoadWriteDelay = 5000;   // 5 seconds
+static const int kFastLoadWriteDelay = 10000;   // 10 seconds
 
 #ifdef PR_LOGGING
 // NSPR_LOG_MODULES=JSComponentLoader:5
 static PRLogModuleInfo *gJSCLLog;
 #endif
 
 #define LOG(args) PR_LOG(gJSCLLog, PR_LOG_DEBUG, args)
 
--- a/modules/libpref/src/nsPrefService.cpp
+++ b/modules/libpref/src/nsPrefService.cpp
@@ -63,17 +63,16 @@
 
 #ifdef MOZ_PROFILESHARING
 #include "nsIProfileSharingSetup.h"
 #include "nsSharedPrefHandler.h"
 #endif
 
 // Definitions
 #define INITIAL_PREF_FILES 10
-#define PREF_READ_BUFFER_SIZE 4096
 
 // Prototypes
 #ifdef MOZ_PROFILESHARING
 static PRBool isSharingEnabled();
 #endif
 
 static nsresult openPrefFile(nsIFile* aFile);
 static nsresult pref_InitInitialObjects(void);
@@ -581,45 +580,56 @@ static PRBool isSharingEnabled()
   }
   return gSharingEnabled;
 }
 #endif
 
 static nsresult openPrefFile(nsIFile* aFile)
 {
   nsCOMPtr<nsIInputStream> inStr;
-  char      readBuf[PREF_READ_BUFFER_SIZE];
 
 #if MOZ_TIMELINE
   {
     nsCAutoString str;
     aFile->GetNativePath(str);
     NS_TIMELINE_MARK_FUNCTION1("load pref file", str.get());
   }
 #endif
 
   nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), aFile);
   if (NS_FAILED(rv)) 
     return rv;        
 
+  PRInt64 fileSize;
+  rv = aFile->GetFileSize(&fileSize);
+  if (NS_FAILED(rv))
+    return rv;
+
+  char *fileBuffer = nsnull;
+  fileBuffer = new char[nsInt64(fileSize)];
+  if (fileBuffer == nsnull)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  PRUint32 amtRead = 0;
+  rv = inStr->Read(fileBuffer, fileSize, &amtRead);
+  if (NS_FAILED(rv)) {
+    delete fileBuffer;
+    return rv;
+  }
+
   PrefParseState ps;
   PREF_InitParseState(&ps, PREF_ReaderCallback, NULL);
-  nsresult rv2 = NS_OK;
-  for (;;) {
-    PRUint32 amtRead = 0;
-    rv = inStr->Read(readBuf, sizeof(readBuf), &amtRead);
-    if (NS_FAILED(rv) || amtRead == 0)
-      break;
+
+  if (!PREF_ParseBuf(&ps, fileBuffer, amtRead))
+    rv = NS_ERROR_FILE_CORRUPTED;
 
-    if (!PREF_ParseBuf(&ps, readBuf, amtRead)) {
-      rv2 = NS_ERROR_FILE_CORRUPTED;
-    }
-  }
   PREF_FinalizeParseState(&ps);
-  return NS_FAILED(rv) ? rv : rv2;        
+  delete fileBuffer;
+
+  return rv;        
 }
 
 /*
  * some stuff that gets called from Pref_Init()
  */
 
 static int
 pref_CompareFileNames(nsIFile* aFile1, nsIFile* aFile2, void* /*unused*/)
--- a/xpcom/io/nsFastLoadFile.cpp
+++ b/xpcom/io/nsFastLoadFile.cpp
@@ -625,19 +625,19 @@ nsFastLoadFileReader::SetInputStream(nsI
     nsresult rv = nsBinaryInputStream::SetInputStream(aInputStream);
     mSeekableInput = do_QueryInterface(aInputStream);
     NS_ASSERTION(!mInputStream || mSeekableInput,
                  "FastLoad requires a seekable input stream");
     return rv;
 }
 
 /**
- * XXX tuneme
+ * FIXME: bug #411579 (tune this macro!) Last updated: Jan 2008
  */
-#define MFL_CHECKSUM_BUFSIZE    8192
+#define MFL_CHECKSUM_BUFSIZE    (6 * 8192)
 
 NS_IMETHODIMP
 nsFastLoadFileReader::ComputeChecksum(PRUint32 *aResult)
 {
     nsCOMPtr<nsIInputStream> stream = mInputStream;
     nsCOMPtr<nsISeekableStream> seekable = mSeekableInput;
 
     PRInt64 saveOffset;