added dom obj counting to decide sequential/parallel layout (#10110)

This commit is contained in:
ddh 2016-06-09 00:34:31 +01:00 committed by Michael Howell
parent 6c3e94805f
commit 479a2c1217
5 changed files with 67 additions and 32 deletions

View file

@ -283,6 +283,12 @@ pub struct Document {
last_click_info: DOMRefCell<Option<(Instant, Point2D<f32>)>>,
/// https://html.spec.whatwg.org/multipage/#ignore-destructive-writes-counter
ignore_destructive_writes_counter: Cell<u32>,
/// Track the total number of elements in this DOM's tree.
/// This is sent to the layout thread every time a reflow is done;
/// layout uses this to determine if the gains from parallel layout will be worth the overhead.
///
/// See also: https://github.com/servo/servo/issues/10110
dom_count: Cell<u32>,
}
#[derive(JSTraceable, HeapSizeOf)]
@ -454,6 +460,22 @@ impl Document {
self.base_element.set(base.r());
}
pub fn dom_count(&self) -> u32 {
self.dom_count.get()
}
/// This is called by `bind_to_tree` when a node is added to the DOM.
/// The internal count is used by layout to determine whether to be sequential or parallel.
/// (it's sequential for small DOMs)
pub fn increment_dom_count(&self) {
self.dom_count.set(self.dom_count.get() + 1);
}
/// This is called by `unbind_from_tree` when a node is removed from the DOM.
pub fn decrement_dom_count(&self) {
self.dom_count.set(self.dom_count.get() - 1);
}
pub fn quirks_mode(&self) -> QuirksMode {
self.quirks_mode.get()
}
@ -1880,6 +1902,7 @@ impl Document {
target_element: MutNullableHeap::new(None),
last_click_info: DOMRefCell::new(None),
ignore_destructive_writes_counter: Default::default(),
dom_count: Cell::new(1),
}
}