From e7432cda09b5b60d2f21e2b0a689dc88132a0567 Mon Sep 17 00:00:00 2001 From: Sebastian C Date: Mon, 19 May 2025 13:50:22 -0500 Subject: [PATCH] Add memory reporting for public suffix list (#37049) Plumbs in the memory reporting into resource_thread since that's where the other user of the public suffix list (HSTS) reports. Testing: Checked about:memory on servo.org Signed-off-by: Sebastian C --- components/net/resource_thread.rs | 18 +++++++++++++----- components/shared/net/pub_domains.rs | 8 +++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index 4077256d6ca..89f76b3ca68 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -24,6 +24,7 @@ use log::{debug, trace, warn}; use malloc_size_of::MallocSizeOf; use net_traits::blob_url_store::parse_blob_url; use net_traits::filemanager_thread::FileTokenCheck; +use net_traits::pub_domains::public_suffix_list_size_of; use net_traits::request::{Destination, RequestBuilder, RequestId}; use net_traits::response::{Response, ResponseInit}; use net_traits::storage_thread::StorageThreadMsg; @@ -287,11 +288,18 @@ impl ResourceChannelManager { perform_memory_report(|ops| { let mut reports = public_http_state.memory_reports("public", ops); reports.extend(private_http_state.memory_reports("private", ops)); - reports.push(Report { - path: path!["hsts-preload-list"], - kind: ReportKind::ExplicitJemallocHeapSize, - size: hsts::PRELOAD_LIST_ENTRIES.size_of(ops), - }); + reports.extend(vec![ + Report { + path: path!["hsts-preload-list"], + kind: ReportKind::ExplicitJemallocHeapSize, + size: hsts::PRELOAD_LIST_ENTRIES.size_of(ops), + }, + Report { + path: path!["public-suffix-list"], + kind: ReportKind::ExplicitJemallocHeapSize, + size: public_suffix_list_size_of(ops), + }, + ]); msg.send(ProcessReports::new(reports)); }) } diff --git a/components/shared/net/pub_domains.rs b/components/shared/net/pub_domains.rs index cbbb2b465b2..6e6f883cd2f 100644 --- a/components/shared/net/pub_domains.rs +++ b/components/shared/net/pub_domains.rs @@ -19,9 +19,11 @@ use std::iter::FromIterator; use std::sync::LazyLock; use embedder_traits::resources::{self, Resource}; +use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; +use malloc_size_of_derive::MallocSizeOf; use servo_url::{Host, ImmutableOrigin, ServoUrl}; -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, MallocSizeOf)] pub struct PubDomainRules { rules: HashSet, wildcards: HashSet, @@ -30,6 +32,10 @@ pub struct PubDomainRules { static PUB_DOMAINS: LazyLock = LazyLock::new(load_pub_domains); +pub fn public_suffix_list_size_of(ops: &mut MallocSizeOfOps) -> usize { + PUB_DOMAINS.size_of(ops) +} + impl<'a> FromIterator<&'a str> for PubDomainRules { fn from_iter(iter: T) -> Self where