Enable PageDiscardingHelper on Android [chromium/src : main]

0 views
Skip to first unread message

Vovo Yang (Gerrit)

unread,
Sep 8, 2025, 7:36:28 AMSep 8
to Chromium Metrics Reviews, Chromium LUCI CQ, AyeAye, chromium...@chromium.org, asvitkine...@chromium.org, chrome-gr...@chromium.org, performance-m...@chromium.org
Attention needed from Joe Mason

Vovo Yang voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Joe Mason
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I86b08716a22f7e92a792da9283d1d379c7c8bbf1
Gerrit-Change-Number: 6904479
Gerrit-PatchSet: 12
Gerrit-Owner: Vovo Yang <vo...@chromium.org>
Gerrit-Reviewer: Joe Mason <joenot...@google.com>
Gerrit-Reviewer: Vovo Yang <vo...@chromium.org>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-Attention: Joe Mason <joenot...@google.com>
Gerrit-Comment-Date: Mon, 08 Sep 2025 11:36:04 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Joe Mason (Gerrit)

unread,
Sep 8, 2025, 3:07:33 PMSep 8
to Vovo Yang, Tom Lukaszewicz, Shin Kawamura, Chromium Metrics Reviews, Chromium LUCI CQ, AyeAye, chromium...@chromium.org, asvitkine...@chromium.org, chrome-gr...@chromium.org, performance-m...@chromium.org
Attention needed from Vovo Yang

Joe Mason voted and added 13 comments

Votes added by Joe Mason

Code-Review+1

13 comments

Patchset-level comments
File-level comment, Patchset 12 (Latest):
Joe Mason . resolved

LGTM with nits.

File chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.cc
Line 286, Patchset 12 (Latest): performance_manager::policies::PageDiscardingHelper>());
Joe Mason . unresolved

Nit: it's hard to keep track of the same object created in two spots in the same file. How about moving the existing PageDiscardingHelper outside the #if and changing it to something like:

```
#if BUILDFLAG(IS_ANDROID)
const bool need_page_discarding_helper =
base::FeatureList::IsEnabled(features::kWebContentsDiscard);
#else
const bool need_page_discarding_helper = true;
#endif
if (need_page_discarding_helper) {
graph->PassToGraph(...);
}
```
File chrome/browser/performance_manager/mechanisms/page_discarder.cc
Line 20, Patchset 12 (Latest):#include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom-forward.h"
Joe Mason . unresolved

Nit: this isn't needed because page_discarder.h file already includes `lifecycle_unit_state.mojom.h`.

Technically the .h should include `lifecycle_unit_state.mojom-forward.h` and the .cc should include `lifecycle_unit_state.mojom.h` so if you want to make that cleanup while you're here, feel free.

Line 23, Patchset 12 (Latest):using ::mojom::LifecycleUnitDiscardReason;
Joe Mason . unresolved

Nit: instead of this, please just change `PageDiscarder::DiscardPageNode` to use `::mojom::LifecycleUnitDiscardReason`. The header file already uses the mojom symbol, leaving it in the .cc file was an oversight.

Line 65, Patchset 12 (Latest): if (contents && base::FeatureList::IsEnabled(features::kWebContentsDiscard)) {
Joe Mason . unresolved

Nit: can it actually get here with out the feature enabled? If not, I'd CHECK this before the `if` instead of making it part of the condition.

Actually this whole `if` isn't needed because there's an `if (!contents)` block just above that does the exact same thing.

Also the `memory_footprint_estimate` is the same between the Android and non-Android branches, and (a) it's not that expensive to calculate, (b) null `lifecycle_unit` should be rare, or even impossible.

So I would structure this as:

```
CHECK(contents, base::NotFatalUntil::M140);
if (!contents) {
outcome = DiscardPageOnUIThreadOutcome::kNoContents;
return std::nullopt;
}
  base::ByteCount memory_footprint_estimate =
user_tuning::GetDiscardedMemoryEstimateForPage(page_node);
#if BUILDFLAG(IS_ANDROID)
CHECK(base::FeatureList::IsEnabled(features::kWebContentsDiscard));
resource_coordinator::AttemptFastKillForDiscard(contents.get(),
discard_reason);
contents->Discard(base::NullCallback());
#else
auto* lifecycle_unit =
resource_coordinator::TabLifecycleUnitSource::GetTabLifecycleUnitExternal(
contents.get());
if (!lifecycle_unit) {
return std::nullopt;
}
  if (!lifecycle_unit->DiscardTab(discard_reason,
memory_footprint_estimate.InKiB())) {
outcome = DiscardPageOnUIThreadOutcome::kDiscardTabFailure;
return std::nullopt;
}
#endif
  outcome = DiscardPageOnUIThreadOutcome::kSuccess;
return memory_footprint_estimate;
}
```
File chrome/browser/resource_coordinator/tab_lifecycle_unit.h
Line 150, Patchset 12 (Parent): void AttemptFastKillForDiscard(content::WebContents* web_contents,
Joe Mason . resolved

Nice cleanup! This has no reason to be in this class.

File chrome/browser/resource_coordinator/tab_lifecycle_unit.cc
Line 45, Patchset 12 (Latest):#include "content/public/browser/render_frame_host.h"
Joe Mason . unresolved

Nit: this is also unused now.

File chrome/browser/resource_coordinator/utils.h
Line 26, Patchset 12 (Latest):// This function is exposed for performance manager PageDiscarder in Android
Joe Mason . unresolved

Nit: I think this comment isn't needed. This is a good place for this function in all cases.

Line 10, Patchset 12 (Latest):#include "chrome/browser/resource_coordinator/lifecycle_unit.h"
Joe Mason . unresolved

Nit: to avoid another dependency on lifecycle_unit.h just for the typedef, I'd prefer to include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom-forward.h" and use `::mojom::LifecycleUnitDiscardReason` in this file. (I'm gradually migrating away from lifecycle_unit.h.)

If you do that, include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom.h" in the .cc file to get the full enum definition.

Line 8, Patchset 12 (Latest):#include <stdint.h>
Joe Mason . unresolved

Nit: this include should be in the .cc file.

File chrome/browser/resource_coordinator/utils.cc
Line 38, Patchset 12 (Latest): content::RenderFrameHost* main_frame = web_contents->GetPrimaryMainFrame();
Joe Mason . unresolved

Nit: please #include "content/public/browser/render_frame_host.h" for IWYU.

Line 39, Patchset 12 (Latest): CHECK(main_frame);
Joe Mason . unresolved

Nit: please #include "base/check.h" for IWYU.

Line 49, Patchset 12 (Latest):#if BUILDFLAG(IS_CHROMEOS)
Joe Mason . unresolved

Nit: please #include "build/build_config.h" for IWYU.

Open in Gerrit

Related details

Attention is currently required from:
  • Vovo Yang
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I86b08716a22f7e92a792da9283d1d379c7c8bbf1
Gerrit-Change-Number: 6904479
Gerrit-PatchSet: 12
Gerrit-Owner: Vovo Yang <vo...@chromium.org>
Gerrit-Reviewer: Joe Mason <joenot...@google.com>
Gerrit-Reviewer: Vovo Yang <vo...@chromium.org>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Shin Kawamura <kaw...@google.com>
Gerrit-CC: Tom Lukaszewicz <tl...@chromium.org>
Gerrit-Attention: Vovo Yang <vo...@chromium.org>
Gerrit-Comment-Date: Mon, 08 Sep 2025 19:07:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Vovo Yang (Gerrit)

unread,
Sep 8, 2025, 11:40:50 PMSep 8
to Tom Lukaszewicz, Shin Kawamura, Chromium Metrics Reviews, Chromium LUCI CQ, AyeAye, chromium...@chromium.org, asvitkine...@chromium.org, chrome-gr...@chromium.org, performance-m...@chromium.org
Attention needed from Joe Mason

Vovo Yang added 13 comments

Patchset-level comments
File-level comment, Patchset 13 (Latest):
Vovo Yang . resolved

Thanks for your review.

File chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.cc
Line 286, Patchset 12: performance_manager::policies::PageDiscardingHelper>());
Joe Mason . resolved

Nit: it's hard to keep track of the same object created in two spots in the same file. How about moving the existing PageDiscardingHelper outside the #if and changing it to something like:

```
#if BUILDFLAG(IS_ANDROID)
const bool need_page_discarding_helper =
base::FeatureList::IsEnabled(features::kWebContentsDiscard);
#else
const bool need_page_discarding_helper = true;
#endif
if (need_page_discarding_helper) {
graph->PassToGraph(...);
}
```
Vovo Yang

Done

File chrome/browser/performance_manager/mechanisms/page_discarder.cc
Line 20, Patchset 12:#include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom-forward.h"
Joe Mason . resolved

Nit: this isn't needed because page_discarder.h file already includes `lifecycle_unit_state.mojom.h`.

Technically the .h should include `lifecycle_unit_state.mojom-forward.h` and the .cc should include `lifecycle_unit_state.mojom.h` so if you want to make that cleanup while you're here, feel free.

Vovo Yang

Done

Line 23, Patchset 12:using ::mojom::LifecycleUnitDiscardReason;
Joe Mason . resolved

Nit: instead of this, please just change `PageDiscarder::DiscardPageNode` to use `::mojom::LifecycleUnitDiscardReason`. The header file already uses the mojom symbol, leaving it in the .cc file was an oversight.

Vovo Yang

Done

Line 65, Patchset 12: if (contents && base::FeatureList::IsEnabled(features::kWebContentsDiscard)) {
Joe Mason . resolved
Vovo Yang

Done

File chrome/browser/resource_coordinator/tab_lifecycle_unit.cc
Line 45, Patchset 12:#include "content/public/browser/render_frame_host.h"
Joe Mason . resolved

Nit: this is also unused now.

Vovo Yang

Done

File chrome/browser/resource_coordinator/utils.h
Line 26, Patchset 12:// This function is exposed for performance manager PageDiscarder in Android
Joe Mason . resolved

Nit: I think this comment isn't needed. This is a good place for this function in all cases.

Vovo Yang

Done

Line 10, Patchset 12:#include "chrome/browser/resource_coordinator/lifecycle_unit.h"
Joe Mason . resolved

Nit: to avoid another dependency on lifecycle_unit.h just for the typedef, I'd prefer to include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom-forward.h" and use `::mojom::LifecycleUnitDiscardReason` in this file. (I'm gradually migrating away from lifecycle_unit.h.)

If you do that, include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom.h" in the .cc file to get the full enum definition.

Vovo Yang

Done

Line 8, Patchset 12:#include <stdint.h>
Joe Mason . resolved

Nit: this include should be in the .cc file.

Vovo Yang

Removed unused include.

File chrome/browser/resource_coordinator/utils.cc
Line 38, Patchset 12: content::RenderFrameHost* main_frame = web_contents->GetPrimaryMainFrame();
Joe Mason . resolved

Nit: please #include "content/public/browser/render_frame_host.h" for IWYU.

Vovo Yang

Done

Line 39, Patchset 12: CHECK(main_frame);
Joe Mason . resolved

Nit: please #include "base/check.h" for IWYU.

Vovo Yang

Done

Line 49, Patchset 12:#if BUILDFLAG(IS_CHROMEOS)
Joe Mason . resolved

Nit: please #include "build/build_config.h" for IWYU.

Vovo Yang

Done

File chrome/browser/ui/webui/discards/discards_ui.cc
Line 332, Patchset 13 (Latest): return;
Vovo Yang . resolved

This is necessary to ensure PageDiscarder::DiscardPageNode() is not called when kWebContentsDiscard is disabled.

Open in Gerrit

Related details

Attention is currently required from:
  • Joe Mason
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I86b08716a22f7e92a792da9283d1d379c7c8bbf1
Gerrit-Change-Number: 6904479
Gerrit-PatchSet: 13
Gerrit-Owner: Vovo Yang <vo...@chromium.org>
Gerrit-Reviewer: Joe Mason <joenot...@google.com>
Gerrit-Reviewer: Vovo Yang <vo...@chromium.org>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Shin Kawamura <kaw...@google.com>
Gerrit-CC: Tom Lukaszewicz <tl...@chromium.org>
Gerrit-Attention: Joe Mason <joenot...@google.com>
Gerrit-Comment-Date: Tue, 09 Sep 2025 03:40:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Joe Mason <joenot...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Joe Mason (Gerrit)

unread,
Sep 9, 2025, 10:49:05 AMSep 9
to Vovo Yang, Tom Lukaszewicz, Shin Kawamura, Chromium Metrics Reviews, Chromium LUCI CQ, AyeAye, chromium...@chromium.org, asvitkine...@chromium.org, chrome-gr...@chromium.org, performance-m...@chromium.org
Attention needed from Vovo Yang

Joe Mason voted and added 1 comment

Votes added by Joe Mason

Code-Review+1

1 comment

File chrome/browser/ui/webui/discards/discards_ui.cc
Vovo Yang . resolved

This is necessary to ensure PageDiscarder::DiscardPageNode() is not called when kWebContentsDiscard is disabled.

Joe Mason

Ack. It would be great to remove the "Discard" button when it's disabled, but this is just a testing UI so it's not a big deal. That can be another CL if you think it's worth it.

Open in Gerrit

Related details

Attention is currently required from:
  • Vovo Yang
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I86b08716a22f7e92a792da9283d1d379c7c8bbf1
Gerrit-Change-Number: 6904479
Gerrit-PatchSet: 14
Gerrit-Owner: Vovo Yang <vo...@chromium.org>
Gerrit-Reviewer: Joe Mason <joenot...@google.com>
Gerrit-Reviewer: Vovo Yang <vo...@chromium.org>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Shin Kawamura <kaw...@google.com>
Gerrit-CC: Tom Lukaszewicz <tl...@chromium.org>
Gerrit-Attention: Vovo Yang <vo...@chromium.org>
Gerrit-Comment-Date: Tue, 09 Sep 2025 14:49:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Vovo Yang <vo...@chromium.org>
satisfied_requirement
open
diffy

Vovo Yang (Gerrit)

unread,
Sep 9, 2025, 10:55:17 AMSep 9
to Tom Lukaszewicz, Shin Kawamura, Chromium Metrics Reviews, Chromium LUCI CQ, AyeAye, chromium...@chromium.org, asvitkine...@chromium.org, chrome-gr...@chromium.org, performance-m...@chromium.org

Vovo Yang voted Commit-Queue+2

Commit-Queue+2
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I86b08716a22f7e92a792da9283d1d379c7c8bbf1
Gerrit-Change-Number: 6904479
Gerrit-PatchSet: 14
Gerrit-Owner: Vovo Yang <vo...@chromium.org>
Gerrit-Reviewer: Joe Mason <joenot...@google.com>
Gerrit-Reviewer: Vovo Yang <vo...@chromium.org>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Shin Kawamura <kaw...@google.com>
Gerrit-CC: Tom Lukaszewicz <tl...@chromium.org>
Gerrit-Comment-Date: Tue, 09 Sep 2025 14:54:49 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Chromium LUCI CQ (Gerrit)

unread,
Sep 9, 2025, 10:58:45 AM (14 days ago) Sep 9
to Vovo Yang, Tom Lukaszewicz, Shin Kawamura, Chromium Metrics Reviews, AyeAye, chromium...@chromium.org, asvitkine...@chromium.org, chrome-gr...@chromium.org, performance-m...@chromium.org

Chromium LUCI CQ submitted the change

Change information

Commit message:
Enable PageDiscardingHelper on Android

Only enabled when feature WebContentsDiscard is enabled.
PageDiscardingHelper is only used by chrome://discards on Android.

NO_IFTTT=move LINT.IfChange block to another file
Bug: b:399740817
Change-Id: I86b08716a22f7e92a792da9283d1d379c7c8bbf1
Commit-Queue: Vovo Yang <vo...@chromium.org>
Reviewed-by: Joe Mason <joenot...@google.com>
Cr-Commit-Position: refs/heads/main@{#1513078}
Files:
  • M chrome/browser/BUILD.gn
  • M chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.cc
  • M chrome/browser/performance_manager/mechanisms/page_discarder.cc
  • M chrome/browser/performance_manager/mechanisms/page_discarder.h
  • M chrome/browser/performance_manager/user_tuning/user_tuning_utils.cc
  • M chrome/browser/resource_coordinator/tab_lifecycle_unit.cc
  • M chrome/browser/resource_coordinator/tab_lifecycle_unit.h
  • M chrome/browser/resource_coordinator/utils.cc
  • M chrome/browser/resource_coordinator/utils.h
  • M chrome/browser/resources/discards/discards_tab.html.ts
  • M chrome/browser/resources/discards/discards_tab.ts
  • M chrome/browser/ui/webui/discards/discards_ui.cc
  • M tools/metrics/histograms/metadata/tab/enums.xml
Change size: M
Delta: 13 files changed, 119 insertions(+), 91 deletions(-)
Branch: refs/heads/main
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Joe Mason
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I86b08716a22f7e92a792da9283d1d379c7c8bbf1
Gerrit-Change-Number: 6904479
Gerrit-PatchSet: 15
Gerrit-Owner: Vovo Yang <vo...@chromium.org>
Gerrit-Reviewer: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
Gerrit-Reviewer: Joe Mason <joenot...@google.com>
Gerrit-Reviewer: Vovo Yang <vo...@chromium.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages