Skip to content

Truly independent web browser

LibWeb: Spare first styles below first styles their rebuild marks

Andreas Klinge73c4fa8d752
diff --git a/Libraries/LibWeb/CSS/UpdateStyle.cpp b/Libraries/LibWeb/CSS/UpdateStyle.cpp
index c8957fa392a..e9744775a81 100644
--- a/Libraries/LibWeb/CSS/UpdateStyle.cpp
+++ b/Libraries/LibWeb/CSS/UpdateStyle.cpp
@@ -345,10 +345,16 @@ void StyleEngineFFI::web_css_install_styles(StyleReactionApplication* applicatio
}
};
+ // NB: No element holds children waiting to arrive where the document has none below it.
+ auto const reveal_waiting = document.descendant_style_arrival_pending() ? CSS::MainEffects::RevealWaiting : CSS::MainEffects::None;
for (auto const& element_effects : ReadonlySpan<InstalledElementEffects> { effects, effect_count }) {
+ auto main_effects = static_cast<CSS::MainEffects>(element_effects.effects);
+ main_effects &= ~CSS::MainEffects::RevealWaiting | reveal_waiting;
+ // NB: The swaps of an element with nothing else to do come with the next element's that has.
+ if (main_effects == CSS::MainEffects::None && element_effects.pseudo_elements_composed == 0)
+ continue;
swap_in_styles_until(element_effects.swaps_begin);
auto* element = element_for(element_effects.style_node);
- auto const main_effects = static_cast<CSS::MainEffects>(element_effects.effects);
// https://drafts.csswg.org/css-transitions-1/#starting
// The transition step compares the style the element held before its swaps with the record they install, so the
// record it held has to outlive its replacement until the step has read it. A step toward a record that declares
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs
index dbfeb0e91ea..d2a4e730feb 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs
@@ -99,6 +99,9 @@ pub(crate) struct StyleInstallation {
/// The records the elements and their pseudo-elements move away from, which their moves and effects read, pinned
/// until the host ends the transaction.
pub(crate) pinned_records: Vec<u64>,
+ /// The elements taking their first style whose parent, its layout tree parent as well, takes its first style in
+ /// this installation too, in the order of their effects, each with the index of those and that parent.
+ first_styles_below_first_styles: Vec<(EffectsIndex, StyleNodeID)>,
}
impl StyleInstallation {
@@ -179,6 +182,21 @@ impl StyleInstallation {
self.keep_effects_with_host_work();
}
+ /// Notes that the element whose effects the installation noted last takes its first style below `parent`, which
+ /// takes its first style too.
+ fn note_first_style_below_first_style(&mut self, parent: StyleNodeID) {
+ let index = u32::try_from(self.effects.len() - 1).expect("an installation's effects fit their index");
+ self.first_styles_below_first_styles.push((EffectsIndex(index), parent));
+ }
+
+ /// Takes the elements `note_first_style_below_first_style` noted.
+ pub(crate) fn take_first_styles_below_first_styles(&mut self) -> Vec<(u32, StyleNodeID)> {
+ std::mem::take(&mut self.first_styles_below_first_styles)
+ .into_iter()
+ .map(|(EffectsIndex(index), parent)| (index, parent))
+ .collect()
+ }
+
/// Keeps the effects of only the elements the main thread has anything to do for beside swapping in their styles.
pub(crate) fn keep_effects_with_host_work(&mut self) {
let before = self.effects.len();
@@ -531,9 +549,18 @@ impl RetainedState {
old_record: old_view.and(computed::FinalStyleRecordID::from_raw(old)),
pseudo_elements,
};
+ let first_style = facts.element_damage.is_none();
let effects = self.main_effects(node, old_view, new_view, facts);
scratch.document_damage.push(effects.damage());
installation.note_element_effects(effects, first_swap);
+ if first_style {
+ scratch.note_first_style(node);
+ if let Some(parent) = parent.filter(|&parent| {
+ scratch.takes_first_style(parent) && self.projection.parent(node) == Some(parent)
+ }) {
+ installation.note_first_style_below_first_style(parent);
+ }
+ }
}
installation.end_element(node, first_swap);
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/install_scratch.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/install_scratch.rs
index 22c701c5414..dcfd95454c4 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/install_scratch.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/install_scratch.rs
@@ -24,7 +24,9 @@ const HOLDING: u32 = 1 << 1;
const HIDDEN_BEFORE_KNOWN: u32 = 1 << 2;
/// The element, or an ancestor of it, was display:none before the installation.
const HIDDEN_BEFORE: u32 = 1 << 3;
-const MARK_BITS: u32 = 4;
+/// The element takes its first style in the installation.
+const FIRST_STYLE: u32 = 1 << 4;
+const MARK_BITS: u32 = 5;
const LAST_GENERATION: u32 = u32::MAX >> MARK_BITS;
#[derive(Default)]
@@ -148,6 +150,16 @@ impl InstallScratch {
}
}
+ /// Notes that `node` takes its first style in the installation.
+ pub(super) fn note_first_style(&mut self, node: StyleNodeID) {
+ self.mark(node, FIRST_STYLE);
+ }
+
+ /// Whether `node` takes its first style in the installation, as noted so far.
+ pub(super) fn takes_first_style(&self, node: StyleNodeID) -> bool {
+ self.marks_of(node) & FIRST_STYLE != 0
+ }
+
/// Empties the scratch for the next installation, keeping its room up to
/// `KEPT_SCRATCH_CAPACITY` entries in each collection.
pub(super) fn recycle(&mut self) {
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_job.rs b/Libraries/LibWeb/Rust/src/css/style/style_job.rs
index b5fa14dd39d..d9a23f02fb1 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_job.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_job.rs
@@ -285,15 +285,26 @@ impl StyleJobAnswer {
}
}
- /// Notes `styled`, what the render side installed of the transaction's style rows.
- pub(crate) fn note_styled(&mut self, styled: crate::layout::StyledRows) {
+ /// Notes `styled`, what the render side installed of the transaction's style rows in `arena`.
+ pub(crate) fn note_styled(&mut self, styled: crate::layout::StyledRows, arena: &crate::layout::LayoutNodeArena) {
debug_assert!(
self.styled_rows.pinned_records.is_empty() && self.styled_rows.rebuilt.is_empty(),
"the render side installs a transaction once"
);
use super::bridge::MainEffects;
- for row in &mut self.installation_for_host.effects {
+ let below_first_styles = self.installation_for_host.take_first_styles_below_first_styles();
+ let mut below_first_styles = below_first_styles.into_iter().peekable();
+ for (index, row) in self.installation_for_host.effects.iter_mut().enumerate() {
let node = row.node();
+ // The boxes of an element with no box are built with its children's, which have none to replace: the build
+ // reaches them from the first of them to have a parent with a box, whatever they are marked with.
+ if let Some((_, parent)) = below_first_styles.next_if(|&(below, _)| below as usize == index)
+ && arena.bound_row(node).is_invalid()
+ && arena.bound_row(parent).is_invalid()
+ {
+ row.effects = row.effects.without(MainEffects::REBUILD);
+ continue;
+ }
// The render side marked the rebuilds of these elements, which leaves the host none to mark.
if styled.rebuilt.binary_search(&node).is_ok() {
row.effects = row.effects.without(MainEffects::REBUILD);
diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rs
index b36f19f46b3..ac681eb9cc6 100644
--- a/Libraries/LibWeb/Rust/src/render_state.rs
+++ b/Libraries/LibWeb/Rust/src/render_state.rs
@@ -237,7 +237,7 @@ impl RenderState {
if !host_work.is_empty() {
self.owed.push(host_work);
}
- answer.note_styled(styled);
+ answer.note_styled(styled, self.arena.arena());
}
/// The style engine, and the layout arena beside it.