Bug 1367416 - Read ahead DLLs on a background thread draft
authorAdam Gashlin <agashlin@mozilla.com>
Wed, 02 Aug 2017 11:18:52 -0700
changeset 619848 be08733c46f88748833a73aef97aeafe81a0fc74
parent 618757 44121dbcac6a9d3ff18ed087a09b3205e5a04db1
child 640524 fe8c5fe79e3ec3566b68dc436119661f0ebe2fbf
push id71848
push useragashlin@mozilla.com
push dateWed, 02 Aug 2017 18:25:56 +0000
bugs1367416, 1362382, 1360167
milestone56.0a1
Bug 1367416 - Read ahead DLLs on a background thread This also reads the dlls for bug 1362382 and bug 1360167. MozReview-Commit-ID: A0qVw6BnohC
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3712,16 +3712,37 @@ AnnotateLSBRelease(void*)
     CrashReporter::AppendAppNotesToCrashReport(desc);
   }
 }
 
 #endif // defined(XP_LINUX) && !defined(ANDROID)
 
 #endif
 
+#ifdef XP_WIN
+static void ReadAheadDll(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");
+}
+#endif
+
 namespace mozilla {
   ShutdownChecksMode gShutdownChecks = SCM_NOTHING;
 } // namespace mozilla
 
 static void SetShutdownChecks() {
   // Set default first. On debug builds we crash. On nightly and local
   // builds we record. Nightlies will then send the info via telemetry,
   // but it is usefull to have the data in about:telemetry in local builds
@@ -4340,16 +4361,25 @@ XREMain::XRE_mainRun()
 
     startupNotifier->Observe(nullptr, APPSTARTUP_TOPIC, nullptr);
   }
 
   nsCOMPtr<nsIAppStartup> appStartup
     (do_GetService(NS_APPSTARTUP_CONTRACTID));
   NS_ENSURE_TRUE(appStartup, NS_ERROR_FAILURE);
 
+
+#ifdef XP_WIN
+  if (!PR_GetEnv("XRE_NO_DLL_READAHEAD"))
+  {
+    PR_CreateThread(PR_USER_THREAD, ReadAheadDlls_ThreadStart, 0, PR_PRIORITY_LOW,
+                    PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+  }
+#endif
+
   if (gDoMigration) {
     nsCOMPtr<nsIFile> file;
     mDirProvider.GetAppDir()->Clone(getter_AddRefs(file));
     file->AppendNative(NS_LITERAL_CSTRING("override.ini"));
     nsINIParser parser;
     nsresult rv = parser.Init(file);
     // if override.ini doesn't exist, also check for distribution.ini
     if (NS_FAILED(rv)) {