Truly independent web browser
LibWeb: Skip the change scan of a transaction nothing reads
Andreas Kling4df37b81b03c
diff --git a/Libraries/LibWeb/Rust/src/css/style/flush.rs b/Libraries/LibWeb/Rust/src/css/style/flush.rsindex f5c6ff778fc..385d7743e0e 100644--- a/Libraries/LibWeb/Rust/src/css/style/flush.rs+++ b/Libraries/LibWeb/Rust/src/css/style/flush.rs@@ -4,6 +4,7 @@* SPDX-License-Identifier: BSD-2-Clause*/+use super::pipeline::projection::NoteChanges;use super::*;/// One clock shared by every phase; rounded cumulative endpoints make the intervals additive.@@ -89,7 +90,13 @@ impl StyleEngine {self.host.deferred_element_style_inputs_are_pending = false;let mut transaction = self.drain_transaction();- self.apply_staged_transaction(&mut transaction);+ // NB: Only the live style reads what a transaction changed. The first transaction of a document brings all of+ // its elements, and a cold pass styles them whatever they changed.+ let note_changes = match self.retained.live_style.is_some() {+ true => NoteChanges::Yes,+ false => NoteChanges::No,+ };+ self.apply_staged_transaction(&mut transaction, note_changes);if let Some(mut live) = self.retained.live_style.take() {live.note_transaction(&self.retained, &transaction);self.retained.live_style = Some(live);diff --git a/Libraries/LibWeb/Rust/src/css/style/ordering.rs b/Libraries/LibWeb/Rust/src/css/style/ordering.rsindex c8fc4c2f014..18a5a6cba6e 100644--- a/Libraries/LibWeb/Rust/src/css/style/ordering.rs+++ b/Libraries/LibWeb/Rust/src/css/style/ordering.rs@@ -4,6 +4,7 @@* SPDX-License-Identifier: BSD-2-Clause*/+use super::pipeline::projection::NoteChanges;use super::*;impl RetainedState {@@ -253,17 +254,17 @@ impl StyleEngine {impl StyleEngine {/// Advance every staged input family to the transaction's final snapshot.- pub(super) fn apply_staged_transaction(&mut self, transaction: &mut StyleUpdate) {+ pub(super) fn apply_staged_transaction(&mut self, transaction: &mut StyleUpdate, note_changes: NoteChanges) {transaction.rule_changes = self.commit_staged_program();self.settle_tree_at_barrier();- self.retained.projection.commit();+ self.retained.projection.commit_noting(note_changes);}/// Normalize and apply the staged inputs into one transaction. A required style observation/// drains here first, so normalization never combines changes across an observation boundary.pub fn take_transaction(&mut self) -> StyleUpdate {let mut transaction = self.drain_transaction();- self.apply_staged_transaction(&mut transaction);+ self.apply_staged_transaction(&mut transaction, NoteChanges::Yes);transaction}diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rsindex c8cac4975e8..a3d1db65c03 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs@@ -976,7 +976,10 @@ impl Projection {////// The transaction that flushes a geometry read's seal publishes the sealed rows instead, and/// the elements written after the seal stay written for the transaction after it.- pub(in crate::css::style) fn commit(&mut self) {+ ///+ /// What a transaction changed is three scans over every written row, for the live style to read. `note_changes`+ /// says whether anything will.+ pub(in crate::css::style) fn commit_noting(&mut self, note_changes: NoteChanges) {let committed = match self.flushing_seal {true => self.sealed.clone().expect("a flushed seal holds its rows"),false => self.rows.clone(),@@ -993,16 +996,18 @@ impl Projection {let hovered = HoveredFacts::of(chain, &self.committed);self.hover.before = std::mem::replace(&mut self.hover.committed, hovered);let mut written = self.written.take();- written.sort_unstable();self.pending_change_scan.clear();self.changes.clear();- for pass in ChangePass::ALL {- for &node in &written {- let slot = node.element_slot();- let before = self.before.get(slot);- let after = self.committed.get(slot);- let hovered = (self.hover.before.contains(node), self.hover.committed.contains(node));- note_changes(pass, node, (before, after), hovered, &mut self.changes);+ if note_changes == NoteChanges::Yes {+ written.sort_unstable();+ for pass in ChangePass::ALL {+ for &node in &written {+ let slot = node.element_slot();+ let before = self.before.get(slot);+ let after = self.committed.get(slot);+ let hovered = (self.hover.before.contains(node), self.hover.committed.contains(node));+ self::note_changes(pass, node, (before, after), hovered, &mut self.changes);+ }}}self.note_watched_key_writes(&written);@@ -1018,6 +1023,11 @@ impl Projection {}}+ #[cfg(test)]+ pub(in crate::css::style) fn commit(&mut self) {+ self.commit_noting(NoteChanges::Yes);+ }+/// Note those of the elements `written`, in the transaction being taken, that carried a watched key or carry one,/// and whose keys moved.fn note_watched_key_writes(&mut self, written: &[StyleNodeID]) {@@ -2009,6 +2019,13 @@ fn relations_of(row: &Row) -> Option<TreeRelations> {})}+/// Whether a transaction being taken notes what it changed.+#[derive(Clone, Copy, PartialEq, Eq)]+pub(in crate::css::style) enum NoteChanges {+ Yes,+ No,+}+#[derive(Clone, Copy, PartialEq, Eq)]enum ChangePass {Relations,