Bug 1628903: Prefetch DLLs to improve disk reads on Windows HDD devices. r=aklotz
authorEmma Malysz <emalysz@mozilla.com>
Wed, 20 May 2020 17:09:24 +0000
changeset 531315 6c10970490f3cc19e644964f583be1a047c08b2c
parent 531314 276021ad5a8a0b149a2fd377dde8666dbebdbc80
child 531316 1704b3d9cf33e89fc6c9783596ccfbe8ca134d8f
push id116570
push usernerli@mozilla.com
push dateWed, 20 May 2020 18:19:48 +0000
treeherderautoland@6c10970490f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1628903
milestone78.0a1
first release with
nightly linux32
6c10970490f3 / 78.0a1 / 20200520213050 / files
nightly linux64
6c10970490f3 / 78.0a1 / 20200520213050 / files
nightly mac
6c10970490f3 / 78.0a1 / 20200520213050 / files
nightly win32
6c10970490f3 / 78.0a1 / 20200520213050 / files
nightly win64
6c10970490f3 / 78.0a1 / 20200520213050 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1628903: Prefetch DLLs to improve disk reads on Windows HDD devices. r=aklotz These DLLs were identified as good candidates for prefetch using the diskify logs. Differential Revision: https://phabricator.services.mozilla.com/D73121
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3573,36 +3573,43 @@ static void AnnotateLSBRelease(void*) {
   if (widget::lsb::GetLSBRelease(dist, desc, release, codename)) {
     CrashReporter::AppendAppNotesToCrashReport(desc);
   }
 }
 
 #endif  // defined(XP_LINUX) && !defined(ANDROID)
 
 #ifdef XP_WIN
-static void ReadAheadDll(const wchar_t* dllName) {
+static void ReadAheadSystemDll(const wchar_t* dllName) {
   wchar_t dllPath[MAX_PATH];
   if (ConstructSystem32Path(dllName, dllPath, MAX_PATH)) {
     ReadAheadLib(dllPath);
   }
 }
 
-static void PR_CALLBACK ReadAheadDlls_ThreadStart(void*) {
-  // Load DataExchange.dll and twinapi.appcore.dll for nsWindow::EnableDragDrop
-  ReadAheadDll(L"DataExchange.dll");
-  ReadAheadDll(L"twinapi.appcore.dll");
-
-  // Load twinapi.dll for WindowsUIUtils::UpdateTabletModeState
-  ReadAheadDll(L"twinapi.dll");
-
-  // Load explorerframe.dll for WinTaskbar::Initialize
-  ReadAheadDll(L"ExplorerFrame.dll");
-
-  // Load WinTypes.dll for nsOSHelperAppService::GetApplicationDescription
-  ReadAheadDll(L"WinTypes.dll");
+static void ReadAheadPackagedDll(const wchar_t* dllName,
+                                 const wchar_t* aGREDir) {
+  wchar_t dllPath[MAX_PATH];
+  swprintf(dllPath, MAX_PATH, L"%s\\%s", aGREDir, dllName);
+  ReadAheadLib(dllPath);
+}
+
+static void PR_CALLBACK ReadAheadDlls_ThreadStart(void* arg) {
+  UniquePtr<wchar_t[]> greDir(static_cast<wchar_t*>(arg));
+
+  // Prefetch the DLLs shipped with firefox
+  ReadAheadPackagedDll(L"libegl.dll", greDir.get());
+  ReadAheadPackagedDll(L"libGLESv2.dll", greDir.get());
+  ReadAheadPackagedDll(L"nssckbi.dll", greDir.get());
+  ReadAheadPackagedDll(L"freebl3.dll", greDir.get());
+  ReadAheadPackagedDll(L"softokn3.dll", greDir.get());
+
+  // Prefetch the system DLLs
+  ReadAheadSystemDll(L"DWrite.dll");
+  ReadAheadSystemDll(L"D3DCompiler_47.dll");
 }
 #endif
 
 #if defined(MOZ_WAYLAND)
 bool IsWaylandDisabled() {
   // Enable Wayland on Gtk+ >= 3.22 where we can expect recent enough
   // compositor & libwayland interface.
   bool disableWayland = (gtk_check_version(3, 22, 0) != nullptr);
@@ -4281,19 +4288,30 @@ nsresult XREMain::XRE_mainRun() {
         do_GetService("@mozilla.org/network/io-service;1"));
     NS_ENSURE_TRUE(io, NS_ERROR_FAILURE);
     io->SetManageOfflineStatus(false);
     io->SetOffline(true);
   }
 
 #ifdef XP_WIN
   if (!PR_GetEnv("XRE_NO_DLL_READAHEAD")) {
-    PR_CreateThread(PR_USER_THREAD, ReadAheadDlls_ThreadStart, 0,
-                    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD,
-                    0);
+    nsCOMPtr<nsIFile> greDir = mDirProvider.GetGREDir();
+    nsAutoString path;
+    rv = greDir->GetPath(path);
+    if (NS_SUCCEEDED(rv)) {
+      PRThread* readAheadThread;
+      wchar_t* pathRaw = new wchar_t[MAX_PATH];
+      wcscpy_s(pathRaw, MAX_PATH, path.get());
+      readAheadThread = PR_CreateThread(
+          PR_USER_THREAD, ReadAheadDlls_ThreadStart, (void*)pathRaw,
+          PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+      if (readAheadThread == NULL) {
+        delete[] pathRaw;
+      }
+    }
   }
 #endif
 
   if (gDoMigration) {
     nsCOMPtr<nsIFile> file;
     mDirProvider.GetAppDir()->Clone(getter_AddRefs(file));
     file->AppendNative(NS_LITERAL_CSTRING("override.ini"));
     nsINIParser parser;