Bug 1363482: Part 3 - Preload string bundles off-thread during startup. r=erahm
authorKris Maglione <maglione.k@gmail.com>
Thu, 31 Aug 2017 17:23:08 -0700
changeset 427912 fff508de0d197bc4a9a70a89d94937bec2b4051c
parent 427911 1920f26831d238822ce8473051707aa210136195
child 427913 807cf55e7f45c4a65d573d976b41e0c4c5a2f3e6
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1363482
milestone57.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 1363482: Part 3 - Preload string bundles off-thread during startup. r=erahm MozReview-Commit-ID: 3Fig5BS9xMz
intl/strres/nsStringBundle.cpp
--- a/intl/strres/nsStringBundle.cpp
+++ b/intl/strres/nsStringBundle.cpp
@@ -20,16 +20,19 @@
 #include "nsIInputStream.h"
 #include "nsIURI.h"
 #include "nsIObserverService.h"
 #include "nsCOMArray.h"
 #include "nsTextFormatter.h"
 #include "nsIErrorService.h"
 #include "nsICategoryManager.h"
 #include "nsContentUtils.h"
+#include "nsStringStream.h"
+#include "mozilla/ResultExtensions.h"
+#include "mozilla/URLPreloader.h"
 
 // for async loading
 #ifdef ASYNC_LOADING
 #include "nsIBinaryInputStream.h"
 #include "nsIStringStream.h"
 #endif
 
 using namespace mozilla;
@@ -88,31 +91,37 @@ nsStringBundle::LoadProperties()
   nsCString scheme;
   uri->GetScheme(scheme);
   if (!scheme.EqualsLiteral("chrome") && !scheme.EqualsLiteral("jar") &&
       !scheme.EqualsLiteral("resource") && !scheme.EqualsLiteral("file") &&
       !scheme.EqualsLiteral("data")) {
     return NS_ERROR_ABORT;
   }
 
-  nsCOMPtr<nsIChannel> channel;
-  rv = NS_NewChannel(getter_AddRefs(channel),
-                     uri,
-                     nsContentUtils::GetSystemPrincipal(),
-                     nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
-                     nsIContentPolicy::TYPE_OTHER);
+  nsCOMPtr<nsIInputStream> in;
 
-  if (NS_FAILED(rv)) return rv;
+  auto result = URLPreloader::ReadURI(uri);
+  if (result.isOk()) {
+    MOZ_TRY(NS_NewCStringInputStream(getter_AddRefs(in), result.unwrap()));
+  } else {
+    nsCOMPtr<nsIChannel> channel;
+    rv = NS_NewChannel(getter_AddRefs(channel),
+                       uri,
+                       nsContentUtils::GetSystemPrincipal(),
+                       nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
+                       nsIContentPolicy::TYPE_OTHER);
 
-  // It's a string bundle.  We expect a text/plain type, so set that as hint
-  channel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
+    if (NS_FAILED(rv)) return rv;
 
-  nsCOMPtr<nsIInputStream> in;
-  rv = channel->Open2(getter_AddRefs(in));
-  if (NS_FAILED(rv)) return rv;
+    // It's a string bundle.  We expect a text/plain type, so set that as hint
+    channel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
+
+    rv = channel->Open2(getter_AddRefs(in));
+    if (NS_FAILED(rv)) return rv;
+  }
 
   NS_ASSERTION(NS_SUCCEEDED(rv) && in, "Error in OpenBlockingStream");
   NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && in, NS_ERROR_FAILURE);
 
   static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
   mProps = do_CreateInstance(kPersistentPropertiesCID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);