From 4233e0f163ce9728dc483f7fe7ff99056aaf1794 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 2 Mar 2016 11:47:02 -0800 Subject: [PATCH] gfx: Box stacking contexts to minimize `memmove` traffic. `memmove` was showing up high in the profile when concatenating and shorting display lists. This change drastically reduces the `memmove` cost in exchange for some minor additional allocation cost. --- components/gfx/display_list/mod.rs | 2 +- components/layout/block.rs | 2 +- components/layout/display_list_builder.rs | 39 +++++++++++------------ components/layout/flex.rs | 2 +- components/layout/flow.rs | 4 +-- components/layout/inline.rs | 2 +- components/layout/list_item.rs | 2 +- components/layout/multicol.rs | 4 +-- components/layout/table.rs | 2 +- components/layout/table_caption.rs | 2 +- components/layout/table_cell.rs | 2 +- components/layout/table_colgroup.rs | 2 +- components/layout/table_row.rs | 2 +- components/layout/table_rowgroup.rs | 2 +- components/layout/table_wrapper.rs | 2 +- 15 files changed, 35 insertions(+), 36 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index aa3c974a1d9..aebdc0882c0 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -508,7 +508,7 @@ pub struct StackingContext { pub layer_info: Option, /// Children of this StackingContext. - pub children: Vec, + pub children: Vec>, } impl StackingContext { diff --git a/components/layout/block.rs b/components/layout/block.rs index a538a768efd..56785dd5eda 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -2109,7 +2109,7 @@ impl Flow for BlockFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.collect_stacking_contexts_for_block(parent_id, contexts) } diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 04beaca2064..5714bdbf6ee 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -67,8 +67,7 @@ pub struct DisplayListBuildState<'a> { } impl<'a> DisplayListBuildState<'a> { - pub fn new(layout_context: &'a LayoutContext, - stacking_context_id: StackingContextId) + pub fn new(layout_context: &'a LayoutContext, stacking_context_id: StackingContextId) -> DisplayListBuildState<'a> { DisplayListBuildState { layout_context: layout_context, @@ -287,7 +286,7 @@ pub trait FragmentDisplayListBuilding { base_flow: &BaseFlow, scroll_policy: ScrollPolicy, mode: StackingContextCreationMode) - -> StackingContext; + -> Box; } fn handle_overlapping_radii(size: &Size2D, radii: &BorderRadii) -> BorderRadii { @@ -1277,7 +1276,7 @@ impl FragmentDisplayListBuilding for Fragment { base_flow: &BaseFlow, scroll_policy: ScrollPolicy, mode: StackingContextCreationMode) - -> StackingContext { + -> Box { let border_box = match mode { StackingContextCreationMode::InnerScrollWrapper => { Rect::new(Point2D::zero(), base_flow.overflow.scroll.size) @@ -1411,18 +1410,18 @@ impl FragmentDisplayListBuilding for Fragment { _ => StackingContextType::Real, }; - StackingContext::new(id, - context_type, - &border_box, - &overflow, - self.effective_z_index(), - filters, - self.style().get_effects().mix_blend_mode, - transform, - perspective, - establishes_3d_context, - scrolls_overflow_area, - layer_info) + Box::new(StackingContext::new(id, + context_type, + &border_box, + &overflow, + self.effective_z_index(), + filters, + self.style().get_effects().mix_blend_mode, + transform, + perspective, + establishes_3d_context, + scrolls_overflow_area, + layer_info)) } fn clipping_region_for_children(&self, @@ -1600,7 +1599,7 @@ impl FragmentDisplayListBuilding for Fragment { pub trait BlockFlowDisplayListBuilding { fn collect_stacking_contexts_for_block(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId; fn build_display_list_for_block(&mut self, state: &mut DisplayListBuildState, @@ -1610,7 +1609,7 @@ pub trait BlockFlowDisplayListBuilding { impl BlockFlowDisplayListBuilding for BlockFlow { fn collect_stacking_contexts_for_block(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { if !self.fragment.establishes_stacking_context() && !self.establishes_pseudo_stacking_context() { @@ -1742,7 +1741,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { pub trait InlineFlowDisplayListBuilding { fn collect_stacking_contexts_for_inline(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId; fn build_display_list_for_inline_fragment_at_index(&mut self, state: &mut DisplayListBuildState, @@ -1753,7 +1752,7 @@ pub trait InlineFlowDisplayListBuilding { impl InlineFlowDisplayListBuilding for InlineFlow { fn collect_stacking_contexts_for_inline(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.base.stacking_context_id = parent_id; diff --git a/components/layout/flex.rs b/components/layout/flex.rs index c4e08ed6ffa..5ae07604f99 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -430,7 +430,7 @@ impl Flow for FlexFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } diff --git a/components/layout/flow.rs b/components/layout/flow.rs index cf8b1be451d..6dfd78ec841 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -224,7 +224,7 @@ pub trait Flow: fmt::Debug + Sync + Send + 'static { fn collect_stacking_contexts(&mut self, _parent_id: StackingContextId, - _: &mut Vec) + _: &mut Vec>) -> StackingContextId; /// If this is a float, places it. The default implementation does nothing. @@ -1203,7 +1203,7 @@ impl BaseFlow { pub fn collect_stacking_contexts_for_children(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) { + contexts: &mut Vec>) { for kid in self.children.iter_mut() { kid.collect_stacking_contexts(parent_id, contexts); } diff --git a/components/layout/inline.rs b/components/layout/inline.rs index ed07f339720..291efea790d 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -1750,7 +1750,7 @@ impl Flow for InlineFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.collect_stacking_contexts_for_inline(parent_id, contexts) } diff --git a/components/layout/list_item.rs b/components/layout/list_item.rs index 701ac4ecdf9..337ba76120b 100644 --- a/components/layout/list_item.rs +++ b/components/layout/list_item.rs @@ -151,7 +151,7 @@ impl Flow for ListItemFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index 36815c82533..4b7ac7d8814 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -186,7 +186,7 @@ impl Flow for MulticolFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } @@ -271,7 +271,7 @@ impl Flow for MulticolColumnFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } diff --git a/components/layout/table.rs b/components/layout/table.rs index eb0c57f615a..0c8d8865a8d 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -467,7 +467,7 @@ impl Flow for TableFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } diff --git a/components/layout/table_caption.rs b/components/layout/table_caption.rs index 4bb783154d2..e1706fc53cd 100644 --- a/components/layout/table_caption.rs +++ b/components/layout/table_caption.rs @@ -83,7 +83,7 @@ impl Flow for TableCaptionFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index 0faebcb3cf2..523ea86a5f5 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -193,7 +193,7 @@ impl Flow for TableCellFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } diff --git a/components/layout/table_colgroup.rs b/components/layout/table_colgroup.rs index 9f1a03e7e0b..32d2c693131 100644 --- a/components/layout/table_colgroup.rs +++ b/components/layout/table_colgroup.rs @@ -96,7 +96,7 @@ impl Flow for TableColGroupFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - _: &mut Vec) + _: &mut Vec>) -> StackingContextId { parent_id } diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 7fc8381f76f..45e8bca12ec 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -435,7 +435,7 @@ impl Flow for TableRowFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } diff --git a/components/layout/table_rowgroup.rs b/components/layout/table_rowgroup.rs index 6971df77787..44da4878119 100644 --- a/components/layout/table_rowgroup.rs +++ b/components/layout/table_rowgroup.rs @@ -212,7 +212,7 @@ impl Flow for TableRowGroupFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) } diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index d3224126929..a8e16812efd 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -451,7 +451,7 @@ impl Flow for TableWrapperFlow { fn collect_stacking_contexts(&mut self, parent_id: StackingContextId, - contexts: &mut Vec) + contexts: &mut Vec>) -> StackingContextId { self.block_flow.collect_stacking_contexts(parent_id, contexts) }