Bug 1367416 - Read ahead DLLs on a background thread
This also reads the dlls for
bug 1362382 and
bug 1360167.
MozReview-Commit-ID: A0qVw6BnohC
--- 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)) {