diff options
author | Oriol Brufau <obrufau@igalia.com> | 2025-03-24 13:33:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-24 12:33:44 +0000 |
commit | c09eed759b9533850c51ad0037fe68fab85ba6c5 (patch) | |
tree | 660dc2a9dce65c2f0d6ec7fe718d2af4be8c96c9 /components/layout_2020/layout_box_base.rs | |
parent | efd6e8639369308715e35532b5f29e3bc399f1ce (diff) | |
download | servo-c09eed759b9533850c51ad0037fe68fab85ba6c5.tar.gz servo-c09eed759b9533850c51ad0037fe68fab85ba6c5.zip |
layout: Cache `IndependentNonReplacedContents::layout()` (#36082)
This replaces `IndependentLayout` with `CacheableLayoutResult` and
stores it in `LayoutBoxBase` so it can be reused when we need to lay out
a box multiple times.
This is a generalization of the caching that we had for flexbox, which
is now removed in favor of the new one.
With this, the number of runs per second in the Chromium perf test
`flexbox-deeply-nested-column-flow.html` are multiplied by 3.
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/layout_2020/layout_box_base.rs')
-rw-r--r-- | components/layout_2020/layout_box_base.rs | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/components/layout_2020/layout_box_base.rs b/components/layout_2020/layout_box_base.rs index 0de9987bde7..bb2d37698f1 100644 --- a/components/layout_2020/layout_box_base.rs +++ b/components/layout_2020/layout_box_base.rs @@ -2,15 +2,20 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use std::fmt::{Debug, Formatter}; + +use app_units::Au; use atomic_refcell::AtomicRefCell; use servo_arc::Arc; use style::properties::ComputedValues; -use crate::ConstraintSpace; use crate::context::LayoutContext; -use crate::fragment_tree::BaseFragmentInfo; +use crate::formatting_contexts::Baselines; +use crate::fragment_tree::{BaseFragmentInfo, CollapsedBlockMargins, Fragment, SpecificLayoutInfo}; use crate::geom::SizeConstraint; +use crate::positioned::PositioningContext; use crate::sizing::{ComputeInlineContentSizes, InlineContentSizesResult}; +use crate::{ConstraintSpace, ContainingBlockSize}; /// A box tree node that handles containing information about style and the original DOM /// node or pseudo-element that it is based on. This also handles caching of layout values @@ -18,12 +23,12 @@ use crate::sizing::{ComputeInlineContentSizes, InlineContentSizesResult}; /// passes. /// /// In the future, this will hold layout results to support incremental layout. -#[derive(Debug)] pub(crate) struct LayoutBoxBase { pub base_fragment_info: BaseFragmentInfo, pub style: Arc<ComputedValues>, pub cached_inline_content_size: AtomicRefCell<Option<(SizeConstraint, InlineContentSizesResult)>>, + pub cached_layout_result: AtomicRefCell<Option<CacheableLayoutResultAndInputs>>, } impl LayoutBoxBase { @@ -32,6 +37,7 @@ impl LayoutBoxBase { base_fragment_info, style, cached_inline_content_size: AtomicRefCell::default(), + cached_layout_result: AtomicRefCell::default(), } } @@ -58,3 +64,45 @@ impl LayoutBoxBase { result } } + +impl Debug for LayoutBoxBase { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { + f.debug_struct("LayoutBoxBase").finish() + } +} + +#[derive(Clone)] +pub(crate) struct CacheableLayoutResult { + pub fragments: Vec<Fragment>, + + /// <https://drafts.csswg.org/css2/visudet.html#root-height> + pub content_block_size: Au, + + /// If this layout is for a block container, this tracks the collapsable size + /// of start and end margins and whether or not the block container collapsed through. + pub collapsible_margins_in_children: CollapsedBlockMargins, + + /// The contents of a table may force it to become wider than what we would expect + /// from 'width' and 'min-width'. This is the resulting inline content size, + /// or None for non-table layouts. + pub content_inline_size_for_table: Option<Au>, + + /// The offset of the last inflow baseline of this layout in the content area, if + /// there was one. This is used to propagate baselines to the ancestors of `display: + /// inline-block`. + pub baselines: Baselines, + + /// Whether or not this layout depends on the containing block size. + pub depends_on_block_constraints: bool, + + /// Additional information of this layout that could be used by Javascripts and devtools. + pub specific_layout_info: Option<SpecificLayoutInfo>, +} + +pub(crate) struct CacheableLayoutResultAndInputs { + pub result: CacheableLayoutResult, + + pub containing_block_for_children_size: ContainingBlockSize, + + pub positioning_context: PositioningContext, +} |