mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
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:
parent
add8c51f47
commit
c787688afc
33 changed files with 230 additions and 69 deletions
|
@ -13,6 +13,7 @@ use std::ops::Range;
|
|||
|
||||
use app_units::{Au, MAX_AU, MIN_AU};
|
||||
use euclid::num::Zero;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use servo_arc::Arc;
|
||||
use style::computed_values::float::T as FloatProperty;
|
||||
use style::computed_values::position::T as Position;
|
||||
|
@ -31,7 +32,7 @@ use crate::style_ext::{DisplayInside, PaddingBorderMargin};
|
|||
use crate::{ContainingBlock, PropagatedBoxTreeData};
|
||||
|
||||
/// A floating box.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct FloatBox {
|
||||
/// The formatting context that makes up the content of this box.
|
||||
pub contents: IndependentFormattingContext,
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::vec::IntoIter;
|
|||
|
||||
use app_units::Au;
|
||||
use fonts::FontMetrics;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
|
||||
use super::{InlineContainerState, InlineContainerStateFlags, inline_container_needs_strut};
|
||||
use crate::ContainingBlock;
|
||||
|
@ -17,7 +18,7 @@ use crate::fragment_tree::BaseFragmentInfo;
|
|||
use crate::layout_box_base::LayoutBoxBase;
|
||||
use crate::style_ext::{LayoutStyle, PaddingBorderMargin};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct InlineBox {
|
||||
pub base: LayoutBoxBase,
|
||||
/// The identifier of this inline box in the containing [`super::InlineFormattingContext`].
|
||||
|
@ -56,7 +57,7 @@ impl InlineBox {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, MallocSizeOf)]
|
||||
pub(crate) struct InlineBoxes {
|
||||
/// A collection of all inline boxes in a particular [`super::InlineFormattingContext`].
|
||||
inline_boxes: Vec<ArcRefCell<InlineBox>>,
|
||||
|
@ -162,7 +163,7 @@ impl InlineBoxes {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
||||
pub(super) enum InlineBoxTreePathToken {
|
||||
Start(InlineBoxIdentifier),
|
||||
End(InlineBoxIdentifier),
|
||||
|
@ -183,7 +184,7 @@ impl InlineBoxTreePathToken {
|
|||
/// [`u32`] is used for the index, in order to save space. The value refers to the token
|
||||
/// in the start tree data structure which can be fetched to find the actual index of
|
||||
/// of the [`InlineBox`] in [`InlineBoxes::inline_boxes`].
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, Hash, MallocSizeOf, PartialEq)]
|
||||
pub(crate) struct InlineBoxIdentifier {
|
||||
pub index_of_start_in_tree: u32,
|
||||
pub index_in_inline_boxes: u32,
|
||||
|
|
|
@ -88,6 +88,7 @@ use line::{
|
|||
TextRunLineItem,
|
||||
};
|
||||
use line_breaker::LineBreaker;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use range::Range;
|
||||
use servo_arc::Arc;
|
||||
use style::Zero;
|
||||
|
@ -136,7 +137,7 @@ use crate::{ConstraintSpace, ContainingBlock, PropagatedBoxTreeData};
|
|||
static FONT_SUBSCRIPT_OFFSET_RATIO: f32 = 0.20;
|
||||
static FONT_SUPERSCRIPT_OFFSET_RATIO: f32 = 0.34;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct InlineFormattingContext {
|
||||
/// All [`InlineItem`]s in this [`InlineFormattingContext`] stored in a flat array.
|
||||
/// [`InlineItem::StartInlineBox`] and [`InlineItem::EndInlineBox`] allow representing
|
||||
|
@ -173,14 +174,14 @@ pub(crate) struct InlineFormattingContext {
|
|||
}
|
||||
|
||||
/// A collection of data used to cache [`FontMetrics`] in the [`InlineFormattingContext`]
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct FontKeyAndMetrics {
|
||||
pub key: FontInstanceKey,
|
||||
pub pt_size: Au,
|
||||
pub metrics: FontMetrics,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) enum InlineItem {
|
||||
StartInlineBox(ArcRefCell<InlineBox>),
|
||||
EndInlineBox,
|
||||
|
@ -189,9 +190,9 @@ pub(crate) enum InlineItem {
|
|||
ArcRefCell<AbsolutelyPositionedBox>,
|
||||
usize, /* offset_in_text */
|
||||
),
|
||||
OutOfFlowFloatBox(Arc<FloatBox>),
|
||||
OutOfFlowFloatBox(#[conditional_malloc_size_of] Arc<FloatBox>),
|
||||
Atomic(
|
||||
Arc<IndependentFormattingContext>,
|
||||
#[conditional_malloc_size_of] Arc<IndependentFormattingContext>,
|
||||
usize, /* offset_in_text */
|
||||
Level, /* bidi_level */
|
||||
),
|
||||
|
|
|
@ -12,6 +12,7 @@ use fonts::{
|
|||
};
|
||||
use fonts_traits::ByteIndex;
|
||||
use log::warn;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use range::Range as ServoRange;
|
||||
use servo_arc::Arc;
|
||||
use style::computed_values::text_rendering::T as TextRendering;
|
||||
|
@ -37,9 +38,10 @@ pub(crate) const XI_LINE_BREAKING_CLASS_WJ: u8 = 30;
|
|||
pub(crate) const XI_LINE_BREAKING_CLASS_ZWJ: u8 = 42;
|
||||
|
||||
/// <https://www.w3.org/TR/css-display-3/#css-text-run>
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct TextRun {
|
||||
pub base_fragment_info: BaseFragmentInfo,
|
||||
#[conditional_malloc_size_of]
|
||||
pub parent_style: Arc<ComputedValues>,
|
||||
pub text_range: Range<usize>,
|
||||
|
||||
|
@ -47,6 +49,7 @@ pub(crate) struct TextRun {
|
|||
/// segments, and shaped.
|
||||
pub shaped_text: Vec<TextRunSegment>,
|
||||
pub selection_range: Option<ServoRange<ByteIndex>>,
|
||||
#[conditional_malloc_size_of]
|
||||
pub selected_style: Arc<ComputedValues>,
|
||||
}
|
||||
|
||||
|
@ -64,7 +67,7 @@ enum SegmentStartSoftWrapPolicy {
|
|||
FollowLinebreaker,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct TextRunSegment {
|
||||
/// The index of this font in the parent [`super::InlineFormattingContext`]'s collection of font
|
||||
/// information.
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
use app_units::{Au, MAX_AU};
|
||||
use inline::InlineFormattingContext;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
|
||||
use servo_arc::Arc;
|
||||
use style::Zero;
|
||||
|
@ -53,13 +54,13 @@ mod root;
|
|||
pub(crate) use construct::BlockContainerBuilder;
|
||||
pub use root::{BoxTree, CanvasBackground};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct BlockFormattingContext {
|
||||
pub contents: BlockContainer,
|
||||
pub contains_floats: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) enum BlockContainer {
|
||||
BlockLevelBoxes(Vec<ArcRefCell<BlockLevelBox>>),
|
||||
InlineFormattingContext(InlineFormattingContext),
|
||||
|
@ -76,7 +77,7 @@ impl BlockContainer {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) enum BlockLevelBox {
|
||||
Independent(IndependentFormattingContext),
|
||||
OutOfFlowAbsolutelyPositionedBox(ArcRefCell<AbsolutelyPositionedBox>),
|
||||
|
@ -246,8 +247,9 @@ pub(crate) struct CollapsibleWithParentStartMargin(bool);
|
|||
|
||||
/// The contentes of a BlockContainer created to render a list marker
|
||||
/// for a list that has `list-style-position: outside`.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct OutsideMarker {
|
||||
#[conditional_malloc_size_of]
|
||||
pub list_item_style: Arc<ComputedValues>,
|
||||
pub base: LayoutBoxBase,
|
||||
pub block_container: BlockContainer,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use app_units::Au;
|
||||
use atomic_refcell::AtomicRef;
|
||||
use compositing_traits::display_list::AxesScrollSensitivity;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use script_layout_interface::wrapper_traits::{
|
||||
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
|
||||
};
|
||||
|
@ -32,6 +33,7 @@ use crate::style_ext::{ComputedValuesExt, Display, DisplayGeneratingBox, Display
|
|||
use crate::taffy::{TaffyItemBox, TaffyItemBoxInner};
|
||||
use crate::{DefiniteContainingBlock, PropagatedBoxTreeData};
|
||||
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct BoxTree {
|
||||
/// Contains typically exactly one block-level box, which was generated by the root element.
|
||||
/// There may be zero if that element has `display: none`.
|
||||
|
@ -437,7 +439,7 @@ impl BoxTree {
|
|||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-backgrounds/#root-background>
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, MallocSizeOf)]
|
||||
pub struct CanvasBackground {
|
||||
/// DOM node for the root element
|
||||
pub root_element: OpaqueNode,
|
||||
|
@ -448,6 +450,7 @@ pub struct CanvasBackground {
|
|||
pub from_element: OpaqueNode,
|
||||
|
||||
/// The computed styles to take background properties from.
|
||||
#[conditional_malloc_size_of]
|
||||
pub style: Option<Arc<ComputedValues>>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue