Skip to content

Truly independent web browser

LibWeb: Remove the layout arena and label counters from Internals

Aliaksandr Kalenik23b7ffe1fa2b
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index eca22628768..5f960afb737 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -996,7 +996,7 @@ void Document::finalize()
tear_down_layout_tree();
if (m_layout_node_arena) {
Layout::RustFFI::document_host_clear_callbacks(m_layout_node_arena->host());
- VERIFY(Layout::RustFFI::render_state_layout_counts(m_layout_node_arena->host()).live_slots == 0);
+ VERIFY(Layout::RustFFI::render_state_live_slot_count(m_layout_node_arena->host()) == 0);
m_layout_node_arena->set_document({}, nullptr);
}
CSS::ComputedValuesFFI::rust_custom_property_registry_destroy(m_rust_custom_property_registry);
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index c6879ae05db..31e14e82b9e 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -226,21 +226,6 @@ u64 Internals::accumulated_visual_context_incremental_update_count()
return Layout::RustFFI::document_host_visual_context_tree_incremental_update_count(document.layout_node_arena().host());
}
-u64 Internals::layout_tree_pre_order_label_violation_count()
-{
- // A script reads the render state, which waits for a frame in flight.
- Layout::ForcedReadScope read { window().associated_document() };
- auto& document = window().associated_document();
- return Layout::RustFFI::render_state_pre_order_label_violation_count(
- document.layout_node_arena().host(), Painting::viewport_row_slot(read, document));
-}
-
-u64 Internals::layout_tree_pre_order_relabel_count()
-{
- auto& document = window().associated_document();
- return Layout::RustFFI::render_state_layout_counts(document.layout_node_arena().host()).pre_order_relabels;
-}
-
u64 Internals::visual_context_tree_node_count()
{
// A script reads the render state, which waits for a frame in flight.
@@ -3230,25 +3215,11 @@ u64 Internals::layout_node_identity(DOM::Node& node)
return layout_node ? static_cast<u64>(layout_node->arena_slot_index()) + 1 : 0;
}
-u64 Internals::layout_arena_live_slot_count()
-{
- auto& document = window().associated_document();
- document.update_layout(DOM::UpdateLayoutReason::Debugging);
- return Layout::RustFFI::render_state_layout_counts(document.layout_node_arena().host()).live_slots;
-}
-
void Internals::panic_render_state_for_testing()
{
Layout::RustFFI::render_state_panic_for_testing(window().associated_document().layout_node_arena().host());
}
-u64 Internals::layout_arena_shell_count()
-{
- auto& document = window().associated_document();
- document.update_layout(DOM::UpdateLayoutReason::Debugging);
- return Layout::RustFFI::render_state_shell_count(document.layout_node_arena().host());
-}
-
GC::Ref<JS::Object> Internals::style_cold_pass(bool verify, u32 threads)
{
// A script reads the render state, which waits for a frame in flight.
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 87ee7b3ad10..df7110a62d5 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -63,8 +63,6 @@ public:
u64 visual_context_tree_structural_epoch();
GC::Ref<JS::Object> visual_context_node_indices(DOM::Element&);
void send_mismatched_visual_context_tree_update_to_compositor();
- u64 layout_tree_pre_order_label_violation_count();
- u64 layout_tree_pre_order_relabel_count();
WebIDL::ExceptionOr<void> load_reference_test_metadata();
bool has_completed_initial_paint() const;
@@ -349,9 +347,7 @@ public:
u64 custom_property_environment_identity(DOM::Element&);
u64 layout_style_record_identity(DOM::Element&);
u64 layout_node_identity(DOM::Node&);
- u64 layout_arena_live_slot_count();
void panic_render_state_for_testing();
- u64 layout_arena_shell_count();
GC::Ref<JS::Object> style_cold_pass(bool verify, u32 threads);
GC::Ref<JS::Object> style_live_report(bool verify);
GC::Ref<JS::Object> style_counters();
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index d0fb3cae6b8..79601b13116 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -18,8 +18,6 @@ interface Internals {
unsigned long long visualContextTreeStructuralEpoch();
object visualContextNodeIndices(Element element);
undefined sendMismatchedVisualContextTreeUpdateToCompositor();
- unsigned long long layoutTreePreOrderLabelViolationCount();
- unsigned long long layoutTreePreOrderRelabelCount();
undefined loadReferenceTestMetadata();
readonly attribute boolean hasCompletedInitialPaint;
@@ -443,10 +441,8 @@ interface Internals {
// Stable for the lifetime of a layout node, and zero when the DOM node has no principal
// layout node. Useful for asserting that incremental tree builds preserve unaffected nodes.
unsigned long long layoutNodeIdentity(Node node);
- unsigned long long layoutArenaLiveSlotCount();
// Makes the document's render state panic answering this call, which waits for it: the WebContent process crashes.
undefined panicRenderStateForTesting();
- unsigned long long layoutArenaShellCount();
// Styles the whole document from scratch in a cold pass, without installing anything, and reports what it measured
// and how its answers compared with the records installed.
object styleColdPass(optional boolean verify = true, optional unsigned long threads = 0);
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index c271ac92890..c42b19c1cc3 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -1148,7 +1148,6 @@ pub(crate) struct LayoutNodeArena {
pub(crate) links_held_apart_from_their_containing_blocks: CowSet<NodeSlotId>,
layout_tree_build_stats: FfiLayoutTreeBuildStats,
pre_order_labels: ForkVec<u64>,
- pre_order_relabel_count: u64,
free_list: ForkVec<u32>,
live_count: u32,
default_scroll_shift_anchors: Vec<DefaultScrollShiftAnchorSlot>,
@@ -1285,7 +1284,6 @@ impl LayoutNodeArena {
links_held_apart_from_their_containing_blocks: Default::default(),
layout_tree_build_stats: (FfiLayoutTreeBuildStats::default()),
pre_order_labels: ForkVec::default(),
- pre_order_relabel_count: 0,
free_list: ForkVec::default(),
live_count: 0,
default_scroll_shift_anchors: Vec::new(),
@@ -5050,10 +5048,6 @@ impl LayoutNodeArena {
self.pre_order_labels[id.slot_index() as usize] = label;
}
- pub(crate) fn pre_order_relabel_count(&self) -> u64 {
- self.pre_order_relabel_count
- }
-
pub(crate) fn count_nodes_in_layout_subtree(&self, root: NodeSlotId) -> u64 {
let mut count = 0u64;
self.for_each_node_in_layout_subtree_in_pre_order(root, |_| count += 1);
@@ -5164,7 +5158,6 @@ impl LayoutNodeArena {
self.set_node_pre_order_label(node, lower + step * position_in_subtree);
cursor = self.next_node_in_layout_subtree_in_pre_order(subtree_root, node);
}
- self.pre_order_relabel_count += 1;
true
}
diff --git a/Libraries/LibWeb/Rust/src/painting/stacking_context/verify.rs b/Libraries/LibWeb/Rust/src/painting/stacking_context/verify.rs
index 9bc98decc41..a5d95687fcc 100644
--- a/Libraries/LibWeb/Rust/src/painting/stacking_context/verify.rs
+++ b/Libraries/LibWeb/Rust/src/painting/stacking_context/verify.rs
@@ -45,21 +45,12 @@ struct Verifier<'a> {
arena: &'a LayoutNodeArena,
expected_entries_by_root: HashMap<NodeSlotId, ExpectedEntries>,
expected_roots: Vec<NodeSlotId>,
- previous_label: Option<u64>,
report: Report,
}
impl Verifier<'_> {
fn visit(&mut self, slot: NodeSlotId, enclosing: NodeSlotId) {
let fresh = StackingContextFacts::gather(self.arena, slot, enclosing);
- let label = self.arena.node_pre_order_label(slot);
- if self.previous_label.is_some_and(|previous| label <= previous) {
- self.report.note(format_args!(
- "pre-order label of {slot:?} is not greater than the previous label"
- ));
- }
- self.previous_label = Some(label);
-
match self.arena.paintable_visual_context_record(slot) {
Some(record) => {
let stored = record.stacking_context;
@@ -138,6 +129,21 @@ impl Verifier<'_> {
}
}
+ fn compare_pre_order_labels(&mut self, viewport: NodeSlotId) {
+ let arena = self.arena;
+ let report = &mut self.report;
+ let mut previous_label: Option<u64> = None;
+ arena.for_each_node_in_layout_subtree_in_pre_order(viewport, |slot| {
+ let label = arena.node_pre_order_label(slot);
+ if previous_label.is_some_and(|previous| label <= previous) {
+ report.note(format_args!(
+ "pre-order label of {slot:?} is not greater than the previous label"
+ ));
+ }
+ previous_label = Some(label);
+ });
+ }
+
fn compare_tables(&mut self) {
for root in std::mem::take(&mut self.expected_roots) {
let expected = self
@@ -218,12 +224,12 @@ pub(crate) fn verification_report(arena: &LayoutNodeArena, viewport: NodeSlotId)
arena,
expected_entries_by_root: HashMap::new(),
expected_roots: Vec::new(),
- previous_label: None,
report: Report {
text: String::new(),
line_count: 0,
},
};
+ verifier.compare_pre_order_labels(viewport);
verifier.visit(viewport, NodeSlotId::INVALID);
verifier.compare_tables();
verifier.report.text
diff --git a/Libraries/LibWeb/Rust/src/render_state/devtools.rs b/Libraries/LibWeb/Rust/src/render_state/devtools.rs
index 61e4632b314..fef9a52ca51 100644
--- a/Libraries/LibWeb/Rust/src/render_state/devtools.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/devtools.rs
@@ -8,9 +8,8 @@
use super::{DocumentHost, ScriptForcedRead};
use crate::layout::LayoutNodeArena;
-use crate::layout::node_data::NodeSlotId;
-/// How many layout passes and tree builds a document's layout has run, and how many rows it holds.
+/// How many layout passes and tree builds a document's layout has run.
#[repr(C)]
#[derive(Clone, Copy, Default)]
pub struct FfiLayoutCounts {
@@ -19,8 +18,6 @@ pub struct FfiLayoutCounts {
pub tree_builds: u64,
pub last_tree_build_rebuilt_subtree_roots: u64,
pub last_tree_build_escaped_rebuild_roots: bool,
- pub live_slots: u64,
- pub pre_order_relabels: u64,
}
/// Mints the forced reads of this module's entries; only this module can make one.
@@ -45,7 +42,7 @@ fn read_arena<R>(host: &DocumentHost, read: impl FnOnce(&mut LayoutNodeArena) ->
})
}
-/// How many layout passes and tree builds the document's layout has run, and how many rows it holds.
+/// How many layout passes and tree builds the document's layout has run.
#[unsafe(no_mangle)]
pub extern "C" fn render_state_layout_counts(host: &DocumentHost) -> FfiLayoutCounts {
read_arena(host, |arena| {
@@ -56,30 +53,14 @@ pub extern "C" fn render_state_layout_counts(host: &DocumentHost) -> FfiLayoutCo
tree_builds: tree_builds.builds,
last_tree_build_rebuilt_subtree_roots: tree_builds.last_build_rebuilt_subtree_roots,
last_tree_build_escaped_rebuild_roots: tree_builds.last_build_escaped_rebuild_roots,
- live_slots: arena.live_slot_count().into(),
- pre_order_relabels: arena.pre_order_relabel_count(),
}
})
}
-/// How many rows of the layout subtree `root` heads carry a pre-order label no greater than the row before them.
+/// How many rows the document's layout arena holds.
#[unsafe(no_mangle)]
-pub extern "C" fn render_state_pre_order_label_violation_count(host: &DocumentHost, root: NodeSlotId) -> u64 {
- read_arena(host, |arena| {
- if !arena.slot_is_live(root) {
- return 0;
- }
- let mut violation_count = 0;
- let mut previous_label: Option<u64> = None;
- arena.for_each_node_in_layout_subtree_in_pre_order(root, |node| {
- let label = arena.node_pre_order_label(node);
- if previous_label.is_some_and(|previous| label <= previous) {
- violation_count += 1;
- }
- previous_label = Some(label);
- });
- violation_count
- })
+pub extern "C" fn render_state_live_slot_count(host: &DocumentHost) -> u64 {
+ read_arena(host, |arena| arena.live_slot_count().into())
}
/// How many times scrollable overflow was recalculated outside layout, counting from zero again where `reset`.
@@ -94,9 +75,3 @@ pub extern "C" fn render_state_scrollable_overflow_recalculation_count(host: &Do
}
})
}
-
-/// How many layout nodes the host made for the rows of its document.
-#[unsafe(no_mangle)]
-pub extern "C" fn render_state_shell_count(host: &DocumentHost) -> u32 {
- host.host_tables().shells.borrow().len() as u32
-}
diff --git a/Tests/LibWeb/Text/expected/layout-tree-update/removing-a-subtree-destroys-its-layout-nodes.txt b/Tests/LibWeb/Text/expected/layout-tree-update/removing-a-subtree-destroys-its-layout-nodes.txt
deleted file mode 100644
index b7e00b14ab8..00000000000
--- a/Tests/LibWeb/Text/expected/layout-tree-update/removing-a-subtree-destroys-its-layout-nodes.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-the subtree's boxes have layout nodes: true
-removing it destroys them: true
diff --git a/Tests/LibWeb/Text/expected/layout-tree-update/rows-get-layout-nodes-only-when-asked.txt b/Tests/LibWeb/Text/expected/layout-tree-update/rows-get-layout-nodes-only-when-asked.txt
deleted file mode 100644
index 2bb75072609..00000000000
--- a/Tests/LibWeb/Text/expected/layout-tree-update/rows-get-layout-nodes-only-when-asked.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-more rows than layout nodes: true
-asking for one box makes at most one layout node: true
diff --git a/Tests/LibWeb/Text/expected/stacking-context/layout-tree-mutations-keep-labels-ordered.txt b/Tests/LibWeb/Text/expected/stacking-context/layout-tree-mutations-keep-labels-ordered.txt
index 72cc352ce84..7e7571651ee 100644
--- a/Tests/LibWeb/Text/expected/stacking-context/layout-tree-mutations-keep-labels-ordered.txt
+++ b/Tests/LibWeb/Text/expected/stacking-context/layout-tree-mutations-keep-labels-ordered.txt
@@ -1,11 +1,12 @@
-baseline: violations=0 report-ok=true
-append 5: violations=0 report-ok=true
-prepend 5: violations=0 report-ok=true
-insertions before a fixed reference: violations=0 relabeled=true
-move an existing subtree: violations=0 report-ok=true
-wrap committed inline children in an anonymous block: violations=0 report-ok=true
+baseline: report-ok=true
+append 5: report-ok=true
+prepend 5: report-ok=true
+200 insertions before a fixed reference: report-ok=true
+remove the insertions: report-ok=true
+move an existing subtree: report-ok=true
+wrap committed inline children in an anonymous block: report-ok=true
wrapped span still hit-tests on top: true
-toggle ::first-letter: violations=0 report-ok=true
-drop ::first-letter: violations=0 report-ok=true
-innerHTML with a table: violations=0 report-ok=true
-removals: violations=0 report-ok=true
+toggle ::first-letter: report-ok=true
+drop ::first-letter: report-ok=true
+innerHTML with a table: report-ok=true
+removals: report-ok=true
diff --git a/Tests/LibWeb/Text/expected/stacking-context/layout-tree-relabeling-leaves-insertion-space.txt b/Tests/LibWeb/Text/expected/stacking-context/layout-tree-relabeling-leaves-insertion-space.txt
deleted file mode 100644
index b99f38f1826..00000000000
--- a/Tests/LibWeb/Text/expected/stacking-context/layout-tree-relabeling-leaves-insertion-space.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Relabels stay bounded: true
-Label violations: 0
diff --git a/Tests/LibWeb/Text/input/layout-tree-update/removing-a-subtree-destroys-its-layout-nodes.html b/Tests/LibWeb/Text/input/layout-tree-update/removing-a-subtree-destroys-its-layout-nodes.html
deleted file mode 100644
index e4def4674cd..00000000000
--- a/Tests/LibWeb/Text/input/layout-tree-update/removing-a-subtree-destroys-its-layout-nodes.html
+++ /dev/null
@@ -1,25 +0,0 @@
-<!DOCTYPE html>
-<script src="../include.js"></script>
-<script>
- test(() => {
- const layoutNodesBefore = internals.layoutArenaShellCount();
-
- const fixture = document.createElement("div");
- for (let i = 0; i < 20; ++i) {
- const item = document.createElement("div");
- item.textContent = `item ${i}`;
- fixture.append(item);
- }
- document.body.append(fixture);
- // Asking for every box makes its layout node.
- for (const item of fixture.children)
- item.getBoundingClientRect();
- const layoutNodesWithSubtree = internals.layoutArenaShellCount();
-
- fixture.remove();
- const layoutNodesAfter = internals.layoutArenaShellCount();
-
- println(`the subtree's boxes have layout nodes: ${layoutNodesWithSubtree >= layoutNodesBefore + 20}`);
- println(`removing it destroys them: ${layoutNodesAfter === layoutNodesBefore}`);
- });
-</script>
diff --git a/Tests/LibWeb/Text/input/layout-tree-update/rows-get-layout-nodes-only-when-asked.html b/Tests/LibWeb/Text/input/layout-tree-update/rows-get-layout-nodes-only-when-asked.html
deleted file mode 100644
index 314dc6cdbdc..00000000000
--- a/Tests/LibWeb/Text/input/layout-tree-update/rows-get-layout-nodes-only-when-asked.html
+++ /dev/null
@@ -1,21 +0,0 @@
-<!DOCTYPE html>
-<script src="../include.js"></script>
-<div id="fixture"></div>
-<script>
- test(() => {
- const fixture = document.getElementById("fixture");
- for (let i = 0; i < 50; ++i) {
- const item = document.createElement("div");
- item.append(document.createElement("span"), `item ${i}`);
- fixture.append(item);
- }
- // Each item's text gets a row of its own, and no layout node until something asks for one.
- const rows = internals.layoutArenaLiveSlotCount();
- const layoutNodes = internals.layoutArenaShellCount();
- println(`more rows than layout nodes: ${rows > layoutNodes + 40}`);
-
- // Asking for a box makes its layout node, and only its own.
- fixture.lastElementChild.getBoundingClientRect();
- println(`asking for one box makes at most one layout node: ${internals.layoutArenaShellCount() <= layoutNodes + 1}`);
- });
-</script>
diff --git a/Tests/LibWeb/Text/input/stacking-context/layout-tree-mutations-keep-labels-ordered.html b/Tests/LibWeb/Text/input/stacking-context/layout-tree-mutations-keep-labels-ordered.html
index ba47dc48ef4..76473fc6591 100644
--- a/Tests/LibWeb/Text/input/stacking-context/layout-tree-mutations-keep-labels-ordered.html
+++ b/Tests/LibWeb/Text/input/stacking-context/layout-tree-mutations-keep-labels-ordered.html
@@ -19,8 +19,6 @@
settle();
document.body.appendChild(document.createElement("pre"));
settle();
- const violations = () => internals.layoutTreePreOrderLabelViolationCount();
- const relabels = () => internals.layoutTreePreOrderRelabelCount();
const report = () => internals.stackingContextStructureVerificationReport();
const container = document.getElementById("container");
const ref = document.getElementById("ref");
@@ -29,7 +27,7 @@
action();
settle();
const r = report();
- lines.push(`${name}: violations=${violations()} report-ok=${r === ""}`);
+ lines.push(`${name}: report-ok=${r === ""}`);
if (r !== "")
lines.push(r);
};
@@ -49,16 +47,18 @@
container.insertBefore(div, container.firstChild);
}
});
- const relabelsBeforeInsertions = relabels();
- let insertionsBeforeRelabel = 0;
- while (relabels() === relabelsBeforeInsertions && insertionsBeforeRelabel < 200) {
- const div = document.createElement("div");
- div.textContent = "wedge";
- container.insertBefore(div, ref);
- settle();
- ++insertionsBeforeRelabel;
- }
- lines.push(`insertions before a fixed reference: violations=${violations()} relabeled=${relabels() > relabelsBeforeInsertions}`);
+ step("200 insertions before a fixed reference", () => {
+ for (let i = 0; i < 200; ++i) {
+ const div = document.createElement("div");
+ div.textContent = "wedge";
+ container.insertBefore(div, ref);
+ settle();
+ }
+ });
+ step("remove the insertions", () => {
+ for (const div of [...container.children].filter(child => child.textContent === "wedge"))
+ div.remove();
+ });
step("move an existing subtree", () => {
container.appendChild(document.getElementById("mover"));
});
diff --git a/Tests/LibWeb/Text/input/stacking-context/layout-tree-relabeling-leaves-insertion-space.html b/Tests/LibWeb/Text/input/stacking-context/layout-tree-relabeling-leaves-insertion-space.html
deleted file mode 100644
index 50c2f093be7..00000000000
--- a/Tests/LibWeb/Text/input/stacking-context/layout-tree-relabeling-leaves-insertion-space.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<script src="../include.js"></script>
-<div><div id="target"></div><div>Following sibling</div></div>
-<script>
- test(() => {
- const target = document.getElementById("target");
- document.body.offsetHeight;
- const before = internals.layoutTreePreOrderRelabelCount();
- target.innerHTML = "<div>".repeat(40) + "<span>x</span>".repeat(5000) + "</div>".repeat(40);
- document.body.offsetHeight;
- const relabels = internals.layoutTreePreOrderRelabelCount() - before;
- println(`Relabels stay bounded: ${relabels < 10}`);
- println(`Label violations: ${internals.layoutTreePreOrderLabelViolationCount()}`);
- });
-</script>