layout: Report memory usage for fragment and box trees. (#36553)

Add memory reporter integration for the fragment and box trees that are
persisted in the layout thread.

Testing: Looked at the numbers for https://servo.org and
https://html.spec.whatwg.org/. The former was very small, but the latter
was 700mb.

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-04-18 16:05:15 -04:00 committed by GitHub
parent add8c51f47
commit c787688afc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 230 additions and 69 deletions

View file

@ -11,6 +11,7 @@ use base::id::{BrowsingContextId, PipelineId};
use data_url::DataUrl;
use embedder_traits::ViewportDetails;
use euclid::{Scale, Size2D};
use malloc_size_of_derive::MallocSizeOf;
use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder};
use pixels::Image;
use script_layout_interface::IFrameSize;
@ -37,7 +38,7 @@ use crate::sizing::{ComputeInlineContentSizes, ContentSizes, InlineContentSizesR
use crate::style_ext::{AspectRatio, Clamp, ComputedValuesExt, ContentBoxSizesAndPBM, LayoutStyle};
use crate::{ConstraintSpace, ContainingBlock, SizeConstraint};
#[derive(Debug)]
#[derive(Debug, MallocSizeOf)]
pub(crate) struct ReplacedContents {
pub kind: ReplacedContentKind,
natural_size: NaturalSizes,
@ -61,7 +62,7 @@ pub(crate) struct ReplacedContents {
///
/// * IFrames do not have natural width and height or natural ratio according
/// to <https://drafts.csswg.org/css-images/#intrinsic-dimensions>.
#[derive(Debug)]
#[derive(Debug, MallocSizeOf)]
pub(crate) struct NaturalSizes {
pub width: Option<Au>,
pub height: Option<Au>,
@ -95,6 +96,7 @@ impl NaturalSizes {
}
}
#[derive(MallocSizeOf)]
pub(crate) enum CanvasSource {
WebGL(ImageKey),
Image(ImageKey),
@ -118,25 +120,25 @@ impl fmt::Debug for CanvasSource {
}
}
#[derive(Debug)]
#[derive(Debug, MallocSizeOf)]
pub(crate) struct CanvasInfo {
pub source: CanvasSource,
}
#[derive(Debug)]
#[derive(Debug, MallocSizeOf)]
pub(crate) struct IFrameInfo {
pub pipeline_id: PipelineId,
pub browsing_context_id: BrowsingContextId,
}
#[derive(Debug)]
#[derive(Debug, MallocSizeOf)]
pub(crate) struct VideoInfo {
pub image_key: webrender_api::ImageKey,
}
#[derive(Debug)]
#[derive(Debug, MallocSizeOf)]
pub(crate) enum ReplacedContentKind {
Image(Option<Arc<Image>>),
Image(#[conditional_malloc_size_of] Option<Arc<Image>>),
IFrame(IFrameInfo),
Canvas(CanvasInfo),
Video(Option<VideoInfo>),