Commit 52e168cf authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[webui][ntp] Enable process-per-site

Process-per-site makes all WebUI NTPs share a single renderer process.
This is what the local NTP does and has the following performance
advantages (measured on my linux machine):

* Reduces mean of NewTabPage.LoadTime.WebUINTP (duration from starting
  the NTP navigation until the most visited items are added to the DOM)
  from 271ms to 141ms.

* Reduces memory overhead of opening a new NTP from ~30MB to ~5MB.

NOTE: The aforementioned performance improvements only hold true if
another NTP is open to have the process pre-warmed. The WebUI NTP does
not seem to use the pre-warmed spare renderer.

+ Move existing WebUI NTP browser test to //c/b/ui/webui/new_tab_page.

Bug: 1075641
Change-Id: Id94294eac41e3ab083e8eece567941ef4d40d08b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2220634
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Auto-Submit: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773865}
parent 81868e2b
...@@ -1604,8 +1604,10 @@ bool ChromeContentBrowserClient::ShouldUseProcessPerSite( ...@@ -1604,8 +1604,10 @@ bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
// NTP should use process-per-site. This is a performance optimization to // NTP should use process-per-site. This is a performance optimization to
// reduce process count associated with NTP tabs. // reduce process count associated with NTP tabs.
if (site_url == GURL(chrome::kChromeUINewTabURL)) if (site_url == GURL(chrome::kChromeUINewTabURL) ||
site_url == GURL(chrome::kChromeUINewTabPageURL)) {
return true; return true;
}
// The web footer experiment should share its renderer to not effectively // The web footer experiment should share its renderer to not effectively
// instantiate one per window. See https://crbug.com/993502. // instantiate one per window. See https://crbug.com/993502.
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "chrome/browser/search/ntp_features.h"
class NtpNavigationBrowserTest : public InProcessBrowserTest { class NtpNavigationBrowserTest : public InProcessBrowserTest {
public: public:
NtpNavigationBrowserTest() = default; NtpNavigationBrowserTest() = default;
...@@ -43,30 +41,3 @@ IN_PROC_BROWSER_TEST_F(NtpNavigationBrowserTest, VerifyNtpSiteInstance) { ...@@ -43,30 +41,3 @@ IN_PROC_BROWSER_TEST_F(NtpNavigationBrowserTest, VerifyNtpSiteInstance) {
ASSERT_EQ(local_ntp_url, ASSERT_EQ(local_ntp_url,
web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL()); web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL());
} }
// Subclass to allow running tests against the WebUI NTP implementation.
class WebUiNtpNavigationBrowserTest : public NtpNavigationBrowserTest {
public:
WebUiNtpNavigationBrowserTest() {
feature_list_.InitAndEnableFeature(ntp_features::kWebUI);
}
~WebUiNtpNavigationBrowserTest() override = default;
private:
base::test::ScopedFeatureList feature_list_;
};
// Verify that the WebUI NTP commits in a SiteInstance with the WebUI URL.
IN_PROC_BROWSER_TEST_F(WebUiNtpNavigationBrowserTest,
VerifyWebUiNtpSiteInstance) {
GURL ntp_url(chrome::kChromeUINewTabURL);
ui_test_utils::NavigateToURL(browser(), ntp_url);
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_EQ(ntp_url, web_contents->GetLastCommittedURL());
GURL webui_ntp_url(chrome::kChromeUINewTabPageURL);
ASSERT_EQ(webui_ntp_url,
web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL());
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/search/ntp_features.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
class WebUiNtpBrowserTest : public InProcessBrowserTest {
public:
WebUiNtpBrowserTest() {
feature_list_.InitAndEnableFeature(ntp_features::kWebUI);
}
~WebUiNtpBrowserTest() override = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data");
ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
}
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
embedded_test_server()->StartAcceptingConnections();
}
private:
base::test::ScopedFeatureList feature_list_;
};
// Verify that the WebUI NTP commits in a SiteInstance with the WebUI URL.
IN_PROC_BROWSER_TEST_F(WebUiNtpBrowserTest, VerifyWebUiNtpSiteInstance) {
GURL ntp_url(chrome::kChromeUINewTabURL);
ui_test_utils::NavigateToURL(browser(), ntp_url);
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_EQ(ntp_url, web_contents->GetLastCommittedURL());
GURL webui_ntp_url(chrome::kChromeUINewTabPageURL);
ASSERT_EQ(webui_ntp_url,
web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL());
}
// Verify that the WebUI NTP uses process-per-site.
IN_PROC_BROWSER_TEST_F(WebUiNtpBrowserTest, ProcessPerSite) {
std::vector<content::WebContents*> tabs;
// Open a few NTPs.
for (size_t i = 0; i < 3; i++) {
content::WebContentsAddedObserver tab_observer;
chrome::NewTab(browser());
// Wait for the new tab.
auto* tab = tab_observer.GetWebContents();
ASSERT_TRUE(WaitForLoadStop(tab));
// Sanity check: the NTP should be a WebUI NTP (and not chrome://newtab/ or
// some other NTP).
EXPECT_EQ(GURL(chrome::kChromeUINewTabPageURL).spec(),
EvalJs(tab, "window.location.href",
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
/*world_id=*/1));
tabs.push_back(tab);
}
// Verify that all NTPs share a process.
for (size_t i = 1; i < tabs.size(); i++) {
EXPECT_EQ(tabs[0]->GetMainFrame()->GetProcess(),
tabs[i]->GetMainFrame()->GetProcess());
}
}
...@@ -1345,6 +1345,7 @@ if (!is_android) { ...@@ -1345,6 +1345,7 @@ if (!is_android) {
"../browser/ui/webui/management_ui_browsertest.cc", "../browser/ui/webui/management_ui_browsertest.cc",
"../browser/ui/webui/net_internals/net_internals_ui_browsertest.cc", "../browser/ui/webui/net_internals/net_internals_ui_browsertest.cc",
"../browser/ui/webui/net_internals/net_internals_ui_browsertest.h", "../browser/ui/webui/net_internals/net_internals_ui_browsertest.h",
"../browser/ui/webui/new_tab_page/webui_ntp_browsertest.cc",
"../browser/ui/webui/ntp/new_tab_ui_browsertest.cc", "../browser/ui/webui/ntp/new_tab_ui_browsertest.cc",
"../browser/ui/webui/policy_ui_browsertest.cc", "../browser/ui/webui/policy_ui_browsertest.cc",
"../browser/ui/webui/prefs_internals_browsertest.cc", "../browser/ui/webui/prefs_internals_browsertest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment