Skip to content

Commit

Permalink
Bug 1710671: do SetAcceptLanguages during process preallocation to re…
Browse files Browse the repository at this point in the history
…duce first-use overhead (especially for process-switch) r=dragana,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D114901
  • Loading branch information
Randell Jesup committed May 12, 2021
1 parent 7c255c7 commit 1679bad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
#include "nsBaseDragService.h"
#include "nsDocShellLoadTypes.h"
#include "nsFocusManager.h"
#include "nsHttpHandler.h"
#include "nsIConsoleService.h"
#include "nsIInputStreamChannel.h"
#include "nsILoadGroup.h"
Expand Down Expand Up @@ -2589,7 +2590,13 @@ mozilla::ipc::IPCResult ContentChild::RecvRemoteType(
}

// A method to initialize anything we need during the preallocation phase
void ContentChild::PreallocInit() { EnsureNSSInitializedChromeOrContent(); }
void ContentChild::PreallocInit() {
EnsureNSSInitializedChromeOrContent();

// SetAcceptLanguages() needs to read localized strings (file access),
// which is slow, so do this in prealloc
nsHttpHandler::PresetAcceptLanguages();
}

// Call RemoteTypePrefix() on the result to remove URIs if you want to use this
// for telemetry.
Expand Down
7 changes: 7 additions & 0 deletions netwerk/protocol/http/nsHttpHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,13 @@ static nsresult PrepareAcceptLanguages(const char* i_AcceptLanguages,
&o_AcceptLanguages);
}

// Ensure that we've fetched the AcceptLanguages setting
/* static */
void nsHttpHandler::PresetAcceptLanguages() {
(void)GetInstance();
[[maybe_unused]] nsresult rv = gHttpHandler->SetAcceptLanguages();
}

nsresult nsHttpHandler::SetAcceptLanguages() {
if (!NS_IsMainThread()) {
nsCOMPtr<nsIThread> mainThread;
Expand Down
4 changes: 4 additions & 0 deletions netwerk/protocol/http/nsHttpHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ class nsHttpHandler final : public nsIHttpProtocolHandler,

bool UseHTTPSRRForSpeculativeConnection() const;

// So we can ensure that this is done during process preallocation to
// avoid first-use overhead
static void PresetAcceptLanguages();

private:
nsHttpHandler();

Expand Down

0 comments on commit 1679bad

Please sign in to comment.