Add scroll tree measurement in IOCompositor (#38922)

Adds a new memory report that aggregates the size of all scroll trees
from within all pipelines for each web view.

Testing: Acessing `about:memory`
Fixes: #38726

---------

Signed-off-by: criskell <96352451+criskell@users.noreply.github.com>
This commit is contained in:
criskell 2025-08-26 09:47:04 -03:00 committed by GitHub
parent 55be274777
commit 7339e2b421
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 3 deletions

1
Cargo.lock generated
View file

@ -1409,6 +1409,7 @@ dependencies = [
"servo_allocator",
"servo_config",
"servo_geometry",
"servo_malloc_size_of",
"stylo_traits",
"surfman",
"timers",

View file

@ -35,6 +35,7 @@ gleam = { workspace = true }
ipc-channel = { workspace = true }
libc = { workspace = true }
log = { workspace = true }
malloc_size_of = { workspace = true }
pixels = { path = "../pixels" }
profile_traits = { workspace = true }
servo_allocator = { path = "../allocator" }

View file

@ -29,7 +29,9 @@ use euclid::{Point2D, Rect, Scale, Size2D, Transform3D};
use ipc_channel::ipc::{self, IpcSender, IpcSharedMemory};
use log::{debug, info, trace, warn};
use pixels::{CorsStatus, ImageFrame, ImageMetadata, PixelFormat, RasterImage};
use profile_traits::mem::{ProcessReports, ProfilerRegistration, Report, ReportKind};
use profile_traits::mem::{
ProcessReports, ProfilerRegistration, Report, ReportKind, perform_memory_report,
};
use profile_traits::time::{self as profile_time, ProfilerCategory};
use profile_traits::{path, time_profile};
use servo_config::{opts, pref};
@ -421,7 +423,7 @@ impl IOCompositor {
let ops =
wr_malloc_size_of::MallocSizeOfOps::new(servo_allocator::usable_size, None);
let report = self.global.borrow().webrender_api.report_memory(ops);
let reports = vec![
let mut reports = vec![
Report {
path: path!["webrender", "fonts"],
kind: ReportKind::ExplicitJemallocHeapSize,
@ -438,6 +440,15 @@ impl IOCompositor {
size: report.display_list,
},
];
perform_memory_report(|ops| {
reports.push(Report {
path: path!["compositor", "scroll-tree"],
kind: ReportKind::ExplicitJemallocHeapSize,
size: self.webview_renderers.scroll_trees_memory_usage(ops),
});
});
sender.send(ProcessReports::new(reports));
},

View file

@ -7,7 +7,7 @@ use std::collections::hash_map::{Entry, Values, ValuesMut};
use base::id::WebViewId;
use crate::webview_renderer::UnknownWebView;
use crate::webview_renderer::{UnknownWebView, WebViewRenderer};
#[derive(Debug)]
pub struct WebViewManager<WebView> {
@ -109,6 +109,17 @@ impl<WebView> WebViewManager<WebView> {
}
}
impl WebViewManager<WebViewRenderer> {
pub(crate) fn scroll_trees_memory_usage(
&self,
ops: &mut malloc_size_of::MallocSizeOfOps,
) -> usize {
self.iter()
.map(|renderer| renderer.scroll_trees_memory_usage(ops))
.sum::<usize>()
}
}
#[cfg(test)]
mod test {
use base::id::{BrowsingContextId, Index, PipelineNamespace, PipelineNamespaceId, WebViewId};

View file

@ -22,6 +22,7 @@ use embedder_traits::{
use euclid::{Point2D, Scale, Vector2D};
use fnv::FnvHashSet;
use log::{debug, warn};
use malloc_size_of::MallocSizeOf;
use servo_geometry::DeviceIndependentPixel;
use style_traits::{CSSPixel, PinchZoomFactor};
use webrender_api::units::{DeviceIntPoint, DevicePixel, DevicePoint, DeviceRect, LayoutVector2D};
@ -1001,6 +1002,16 @@ impl WebViewRenderer {
));
self.viewport_description = Some(viewport_description);
}
pub(crate) fn scroll_trees_memory_usage(
&self,
ops: &mut malloc_size_of::MallocSizeOfOps,
) -> usize {
self.pipelines
.values()
.map(|pipeline| pipeline.scroll_tree.size_of(ops))
.sum::<usize>()
}
}
#[derive(Clone, Copy, Debug, PartialEq)]