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 11, 2021
1 parent 51b2bad commit e726c98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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 @@ -2588,7 +2589,11 @@ mozilla::ipc::IPCResult ContentChild::RecvRemoteType(
}

// A method to initialize anything we need during the preallocation phase
void ContentChild::PreallocInit() {}
void ContentChild::PreallocInit() {
// 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();
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 e726c98

Please sign in to comment.