Commit a538eb78 authored by Alex Thayer's avatar Alex Thayer
Browse files

Bug 1651941 - Avoid unnecessary empty StartupCaches r=froydnj

Prior to this patch, we were sending a boolean from InitContentChild (which
creates our StartupCache IPC actors) indicating whether we wanted to collect
new entries from a given process or not. This was so that we wouldn't accept
PutBuffer requests in these processes, since collecting them in one process
would be enough, and we don't want to waste memory. However, we actually
want the cache to be available before we can even get that IPC constructor
to the child process, so there's a window where we accept new entries
no matter what. This patch changes this by sending a boolean argument via
the command line indicating that we want to disable the Startupcache in this
process entirely. We send this when we didn't load a StartupCache off disk,
as this should be the only circumstance in which we're actually collecting
a substantial number of entries in content processes.

Differential Revision: https://phabricator.services.mozilla.com/D83400
parent 6bc1e340
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -1926,8 +1926,7 @@ mozilla::ipc::IPCResult ContentChild::RecvPScriptCacheConstructor(
  return IPC_OK();
}

scache::PStartupCacheChild* ContentChild::AllocPStartupCacheChild(
    const bool& wantCacheData) {
scache::PStartupCacheChild* ContentChild::AllocPStartupCacheChild() {
  return new scache::StartupCacheChild();
}

@@ -1938,8 +1937,8 @@ bool ContentChild::DeallocPStartupCacheChild(
}

mozilla::ipc::IPCResult ContentChild::RecvPStartupCacheConstructor(
    scache::PStartupCacheChild* actor, const bool& wantCacheData) {
  static_cast<scache::StartupCacheChild*>(actor)->Init(wantCacheData);
    scache::PStartupCacheChild* actor) {
  static_cast<scache::StartupCacheChild*>(actor)->Init();
  return IPC_OK();
}

+2 −2
Original line number Diff line number Diff line
@@ -238,12 +238,12 @@ class ContentChild final : public PContentChild,
      PScriptCacheChild*, const FileDescOrError& cacheFile,
      const bool& wantCacheData) override;

  PStartupCacheChild* AllocPStartupCacheChild(const bool& wantCacheData);
  PStartupCacheChild* AllocPStartupCacheChild();

  bool DeallocPStartupCacheChild(PStartupCacheChild*);

  virtual mozilla::ipc::IPCResult RecvPStartupCacheConstructor(
      PStartupCacheChild*, const bool& wantCacheData) override;
      PStartupCacheChild*) override;

  PNeckoChild* AllocPNeckoChild();

+4 −4
Original line number Diff line number Diff line
@@ -2289,7 +2289,8 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {

  auto startupCache = mozilla::scache::StartupCache::GetSingleton();
  if (startupCache) {
    startupCache->AddStartupCacheCmdLineArgs(*mSubprocess, extraArgs);
    startupCache->AddStartupCacheCmdLineArgs(*mSubprocess, GetRemoteType(),
                                             extraArgs);
  }

  // Register ContentParent as an observer for changes to any pref
@@ -3822,9 +3823,8 @@ bool ContentParent::DeallocPScriptCacheParent(PScriptCacheParent* cache) {
  return true;
}

PStartupCacheParent* ContentParent::AllocPStartupCacheParent(
    const bool& wantCacheData) {
  return new scache::StartupCacheParent(wantCacheData);
PStartupCacheParent* ContentParent::AllocPStartupCacheParent() {
  return new scache::StartupCacheParent();
}

bool ContentParent::DeallocPStartupCacheParent(PStartupCacheParent* cache) {
+1 −1
Original line number Diff line number Diff line
@@ -922,7 +922,7 @@ class ContentParent final

  bool DeallocPScriptCacheParent(PScriptCacheParent* shell);

  PStartupCacheParent* AllocPStartupCacheParent(const bool& wantCacheData);
  PStartupCacheParent* AllocPStartupCacheParent();

  bool DeallocPStartupCacheParent(PStartupCacheParent* shell);

+7 −2
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
  char* prefMapSize = nullptr;
  char* scacheHandle = nullptr;
  char* scacheSize = nullptr;
  bool wantsScache = true;
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
  nsCOMPtr<nsIFile> profileDir;
#endif
@@ -151,6 +152,8 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
        return false;
      }
      scacheSize = aArgv[i];
    } else if (strcmp(aArgv[i], "-noScache") == 0) {
      wantsScache = false;
    } else if (strcmp(aArgv[i], "-safeMode") == 0) {
      gSafeMode = true;

@@ -187,8 +190,10 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
    return false;
  }

  if (wantsScache) {
    Unused << mozilla::scache::StartupCache::InitChildSingleton(scacheHandle,
                                                                scacheSize);
  }

  mContent.Init(IOThreadChild::message_loop(), ParentPid(), *parentBuildID,
                IOThreadChild::TakeChannel(), *childID, *isForBrowser);
Loading