Bug 1529551 - Only readahead jars in the parent process. r=aklotz
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 25 Feb 2019 23:40:55 +0000
changeset 461012 2e92db777acff0551795391d97e05a57e051ec9c
parent 461011 575da58a58c7d38702bca83a2e45d95b075d17da
child 461013 faec87a80ed1e4f50a7961b4dd652a682ef339ce
push id35613
push usernerli@mozilla.com
push dateTue, 26 Feb 2019 03:52:35 +0000
treeherdermozilla-central@faec87a80ed1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1529551
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1529551 - Only readahead jars in the parent process. r=aklotz Consequently, since we don't readahead jars in child processes, we don't record jar accesses from child processes. In fact, intertwining jar accesses from child processes with those from the parent process was arguably making things less efficient for the parent process. But this code was written at a time e10s was barely a thing, so it wasn't really thought for a multi-process world. Differential Revision: https://phabricator.services.mozilla.com/D20752
modules/libjar/nsZipArchive.cpp
--- a/modules/libjar/nsZipArchive.cpp
+++ b/modules/libjar/nsZipArchive.cpp
@@ -18,16 +18,17 @@
 #include "nsISupportsUtils.h"
 #include "prio.h"
 #include "plstr.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Logging.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "stdlib.h"
 #include "nsWildCard.h"
+#include "nsXULAppAPI.h"
 #include "nsZipArchive.h"
 #include "nsString.h"
 #include "prenv.h"
 #if defined(XP_WIN)
 #  include <windows.h>
 #endif
 
 // For placement new used for arena allocations of zip file list
@@ -73,16 +74,19 @@ static const uint16_t kSyntheticDate = (
 
 static uint16_t xtoint(const uint8_t *ii);
 static uint32_t xtolong(const uint8_t *ll);
 static uint32_t HashName(const char *aName, uint16_t nameLen);
 
 class ZipArchiveLogger {
  public:
   void Write(const nsACString &zip, const char *entry) const {
+    if (!XRE_IsParentProcess()) {
+      return;
+    }
     if (!fd) {
       char *env = PR_GetEnv("MOZ_JAR_LOG_FILE");
       if (!env) return;
 
       nsCOMPtr<nsIFile> logFile;
       nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(env), false,
                                     getter_AddRefs(logFile));
       if (NS_FAILED(rv)) return;
@@ -586,17 +590,21 @@ nsZipItem *nsZipArchive::CreateZipItem()
 //---------------------------------------------
 nsresult nsZipArchive::BuildFileList(PRFileDesc *aFd) {
   // Get archive size using end pos
   const uint8_t *buf;
   const uint8_t *startp = mFd->mFileData;
   const uint8_t *endp = startp + mFd->mLen;
   MOZ_WIN_MEM_TRY_BEGIN
   uint32_t centralOffset = 4;
-  if (mFd->mLen > ZIPCENTRAL_SIZE &&
+  // Only perform readahead in the parent process. Children processes
+  // don't need readahead when the file has already been readahead by
+  // the parent process, and readahead only really happens for omni.ja,
+  // which is used in the parent process.
+  if (XRE_IsParentProcess() && mFd->mLen > ZIPCENTRAL_SIZE &&
       xtolong(startp + centralOffset) == CENTRALSIG) {
     // Success means optimized jar layout from bug 559961 is in effect
     uint32_t readaheadLength = xtolong(startp);
     if (readaheadLength) {
 #if defined(XP_SOLARIS)
       posix_madvise(const_cast<uint8_t *>(startp), readaheadLength,
                     POSIX_MADV_WILLNEED);
 #elif defined(XP_UNIX)