Truly independent web browser
LibWeb: Ask for records' memory ahead when a job goes through them
Andreas Kling45232487666c
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rsindex 1058e6024d6..e636b0db08f 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs@@ -289,7 +289,13 @@ impl RetainedState {let ordered = std::mem::take(&mut scratch.ordered);let element_damages = self.element_move_damages(live, &ordered);let mut rows = Vec::with_capacity(ordered.len());- for (&node, &element_damage) in ordered.iter().zip(&element_damages) {+ for (index, (&node, &element_damage)) in ordered.iter().zip(&element_damages).enumerate() {+ if let Some(ahead) = ordered+ .get(index + super::records::RECORDS_AHEAD)+ .and_then(|&ahead| live.demanded_record(ahead))+ {+ ahead.prefetch();+ }let Some(record) = live.demanded_record(node) else {continue;};diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rsindex 06d2dc3bf17..411c24809c1 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs@@ -1487,7 +1487,10 @@ impl RetainedRecords {// elements do, one per record and set of pseudo-elements, which elements sharing a style// share.let mut with_pseudo_element_styles: HashMap<(usize, PseudoElementStyles), Arc<Record>> = HashMap::default();- for node in styled {+ for (index, node) in styled.iter().enumerate() {+ if let Some(ahead) = styled.get(index + RECORDS_AHEAD) {+ cells.prefetch_record(*ahead);+ }let slot = node.element_slot();let Some(page) = cells.pages[slot / CELL_PAGE_SIZE].get_mut() else {continue;@@ -1680,6 +1683,21 @@ pub(super) struct RecordCells {/// How many elements a page of record cells holds.const CELL_PAGE_SIZE: usize = 64;+/// How many elements ahead a thread going through the records a pass made on other threads asks for their memory.+pub(super) const RECORDS_AHEAD: usize = 8;++impl RecordCells {+ /// Asks for the memory of the record the pass made for `node`.+ fn prefetch_record(&self, node: StyleNodeID) {+ let slot = node.element_slot();+ if let Some(page) = self.pages[slot / CELL_PAGE_SIZE].get()+ && let Some(held) = page.held[slot % CELL_PAGE_SIZE].get()+ {+ held.record.prefetch();+ }+ }+}+/// The record cells of `CELL_PAGE_SIZE` elements.struct CellPage {/// Elements that share a style hold one record.@@ -2287,6 +2305,12 @@ impl ContainerRecords for Records<'_> {}impl Record {+ /// Asks for the memory of the fields a thread first reads of a record another thread made.+ pub(super) fn prefetch(&self) {+ crate::css::declaration_block::prefetch(std::ptr::from_ref(&self.payloads));+ crate::css::declaration_block::prefetch(std::ptr::from_ref(&self.header));+ }+/// The view of the record, as the computation of the elements inheriting from it reads it.pub(in super::super) fn view(self: &Arc<Self>) -> computed::StyleRecordView<'_> {computed::StyleRecordView {