Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
perf(layout): keep grid and table scratch outside layout boxes
ldm04e453f261fcc
diff --git a/moli-layout/src/paint/cull.rs b/moli-layout/src/paint/cull.rsindex bc486a67d..92e621102 100644--- a/moli-layout/src/paint/cull.rs+++ b/moli-layout/src/paint/cull.rs@@ -253,7 +253,7 @@ whereif !layout_box.style.is_visible() {return PaintCullBounds::Empty;}- let Some(borders) = layout_box.collapsed_table_borders.as_ref() else {+ let Some(borders) = projection.world.collapsed_table_borders.get(&id) else {return PaintCullBounds::Empty;};let mut bounds = PaintCullBounds::Empty;diff --git a/moli-layout/src/paint/table.rs b/moli-layout/src/paint/table.rsindex d91dee723..f29b8d933 100644--- a/moli-layout/src/paint/table.rs+++ b/moli-layout/src/paint/table.rs@@ -20,7 +20,7 @@ pub(super) fn project_collapsed_table_borders<N>(if !layout_box.style.is_visible() {return;}- let Some(borders) = layout_box.collapsed_table_borders.as_ref() else {+ let Some(borders) = projection.world.collapsed_table_borders.get(&id) else {return;};let geometry = &projection.boxes[id.index()];diff --git a/moli-layout/src/projection.rs b/moli-layout/src/projection.rsindex 121841780..336836f5b 100644--- a/moli-layout/src/projection.rs+++ b/moli-layout/src/projection.rs@@ -969,7 +969,10 @@ where},horizontal: layout_box.style.uses_horizontal_writing_mode(),});- let resolved_grid_tracks = layout_box.resolved_grid_tracks.clone();+ let resolved_grid_tracks = world+ .resolved_grid_tracks+ .get(&LayoutBoxId::from_index(geometry.id.index()))+ .cloned();FrozenLayoutBox {geometry,scroll_extent,diff --git a/moli-layout/src/stacking.rs b/moli-layout/src/stacking.rsindex e173e7342..2e4dfff74 100644--- a/moli-layout/src/stacking.rs+++ b/moli-layout/src/stacking.rs@@ -113,7 +113,7 @@ fn emit_context<N>(kind: UnitKind::Contents,sequence: next_sequence(sequence),});- if world.boxes[root.index()].collapsed_table_borders.is_some() {+ if world.collapsed_table_borders.contains_key(&root) {collection.table_collapsed_borders.push(PaintUnit {id: root,kind: UnitKind::TableCollapsedBorders,@@ -240,7 +240,7 @@ fn collect_subtree<N>(for child in ordered_children(world, id) {collect_subtree(world, child, descendant_group, sequence, collection);}- if layout_box.collapsed_table_borders.is_some() {+ if world.collapsed_table_borders.contains_key(&id) {push_unit(collection,group,diff --git a/moli-layout/src/table/collapsed_borders.rs b/moli-layout/src/table/collapsed_borders.rsindex 744176d2e..4a80fd060 100644--- a/moli-layout/src/table/collapsed_borders.rs+++ b/moli-layout/src/table/collapsed_borders.rs@@ -468,7 +468,7 @@ where{world.boxes[part.index()].collapsed_table_border_part = true;}- world.boxes[root.index()].collapsed_table_borders = Some(borders);+ world.collapsed_table_borders.insert(root, borders);}pub(super) fn set_collapsed_border_geometry<N>(@@ -479,7 +479,7 @@ pub(super) fn set_collapsed_border_geometry<N>() whereN: Copy + Debug + Eq + Hash,{- if let Some(borders) = world.boxes[root.index()].collapsed_table_borders.as_mut() {+ if let Some(borders) = world.collapsed_table_borders.get_mut(&root) {borders.set_geometry(columns, rows);}}diff --git a/moli-layout/src/taffy_tree.rs b/moli-layout/src/taffy_tree.rsindex 18b89f523..aca7be84e 100644--- a/moli-layout/src/taffy_tree.rs+++ b/moli-layout/src/taffy_tree.rs@@ -138,6 +138,7 @@ pub(crate) fn prepare_world_layout<N>(whereN: Copy + Debug + Eq + Hash,{+ world.resolved_grid_tracks.clear();for index in 0..world.boxes.len() {world.clear_layout_caches(LayoutBoxId::from_index(index));let layout_box = &mut world.boxes[index];@@ -147,7 +148,6 @@ wherelayout_box.layout_children.clear();layout_box.positioned_containing_block = None;layout_box.inline_static_position = None;- layout_box.resolved_grid_tracks = None;}world.viewport_layout.children.clear();@@ -1880,8 +1880,8 @@ whereelse {return;};- self.boxes[LayoutBoxId::from_taffy(node_id).index()].resolved_grid_tracks =- Some(resolved_grid_tracks);+ self.resolved_grid_tracks+ .insert(LayoutBoxId::from_taffy(node_id), resolved_grid_tracks);}}diff --git a/moli-layout/src/world.rs b/moli-layout/src/world.rsindex d9d8aa7f7..6fee0b314 100644--- a/moli-layout/src/world.rs+++ b/moli-layout/src/world.rs@@ -263,22 +263,11 @@ pub struct LayoutBox<N> {pub(crate) replaced_context: Option<ReplacedContext>,pub(crate) replaced_image: Option<crate::LayoutImageResource>,pub(crate) css_images: crate::source::LayoutCssImageResources,- /// Winning collapsed-table edges owned by the table wrapper for this pass.- ///- /// The record contains only resolved numeric/color/style data. It is- /// produced before Taffy sizing, completed with grid-line geometry after- /// sizing, and consumed once by immutable paint projection.- pub(crate) collapsed_table_borders: Option<crate::table::CollapsedTableBorders>,/// Suppresses ordinary per-box border paint for parts participating in a/// collapsed table. Their authored borders have already entered the table/// owner's conflict-resolution grid.pub(crate) collapsed_table_border_part: bool,pub(crate) inline_formatting_context: bool,- /// Used Grid tracks produced by the numeric layout pass.- ///- /// This is browser-owned canonical geometry rather than a retained Taffy- /// object. It is frozen with the rest of the layout tree for CSSOM reads.- pub(crate) resolved_grid_tracks: Option<LayoutResolvedGridTracks>,pub(crate) table_measure_cache: Option<Box<crate::table::TableMeasureCache>>,pub(crate) unrounded_layout: Layout,pub(crate) final_layout: Layout,@@ -644,6 +633,12 @@ wherepub(crate) box_caches: Vec<Cache>,/// Box-indexed lookup into compact cache storage; usize::MAX is absent.pub(crate) box_cache_slots: Vec<usize>,+ /// Winning collapsed-table edges, computed and consumed in this pass.+ /// Empty slots are not embedded in boxes that do not own a table.+ pub(crate) collapsed_table_borders: HashMap<LayoutBoxId, crate::table::CollapsedTableBorders>,+ /// Used Grid tracks for actual owners. Their canonical result is frozen+ /// for CSSOM before this pass-local map is released.+ pub(crate) resolved_grid_tracks: HashMap<LayoutBoxId, LayoutResolvedGridTracks>,pub(crate) source_mapping: HashMap<N, LayoutBoxId>,pub(crate) display_contents_mapping: HashMap<N, Vec<LayoutBoxId>>,pub(crate) root: LayoutBoxId,@@ -673,6 +668,8 @@ whereboxes: vec![root],box_caches: Vec::new(),box_cache_slots: Vec::new(),+ collapsed_table_borders: HashMap::new(),+ resolved_grid_tracks: HashMap::new(),source_mapping: HashMap::new(),display_contents_mapping: HashMap::new(),root: LayoutBoxId::from_index(0),@@ -1242,10 +1239,8 @@ wherereplaced_context: None,replaced_image: None,css_images: crate::source::LayoutCssImageResources::default(),- collapsed_table_borders: None,collapsed_table_border_part: false,inline_formatting_context: false,- resolved_grid_tracks: None,table_measure_cache: None,unrounded_layout: Layout::with_order(0),final_layout: Layout::with_order(0),