mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Auto merge of #12862 - servo:layout-new, r=emilio
added dom obj counting to decide sequential/parallel layout (#10110) This is a rebased version of #11713 --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #10110 (github issue number if applicable). - [X] There are no tests for these changes because it's an optimization with no visible behavioral changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12862) <!-- Reviewable:end -->
This commit is contained in:
commit
0fe94a6724
7 changed files with 76 additions and 35 deletions
|
@ -284,6 +284,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)]
|
||||
|
@ -455,6 +461,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()
|
||||
}
|
||||
|
@ -1884,6 +1906,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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2151,10 +2151,12 @@ impl VirtualMethods for Element {
|
|||
return;
|
||||
}
|
||||
|
||||
let doc = document_from_node(self);
|
||||
if let Some(ref value) = *self.id_attribute.borrow() {
|
||||
let doc = document_from_node(self);
|
||||
doc.register_named_element(self, value.clone());
|
||||
}
|
||||
// This is used for layout optimization.
|
||||
doc.increment_dom_count();
|
||||
}
|
||||
|
||||
fn unbind_from_tree(&self, context: &UnbindContext) {
|
||||
|
@ -2164,10 +2166,12 @@ impl VirtualMethods for Element {
|
|||
return;
|
||||
}
|
||||
|
||||
let doc = document_from_node(self);
|
||||
if let Some(ref value) = *self.id_attribute.borrow() {
|
||||
let doc = document_from_node(self);
|
||||
doc.unregister_named_element(self, value.clone());
|
||||
}
|
||||
// This is used for layout optimization.
|
||||
doc.decrement_dom_count();
|
||||
}
|
||||
|
||||
fn children_changed(&self, mutation: &ChildrenMutation) {
|
||||
|
|
|
@ -71,7 +71,10 @@ impl VirtualMethods for HTMLHeadElement {
|
|||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
fn bind_to_tree(&self, _tree_in_doc: bool) {
|
||||
fn bind_to_tree(&self, tree_in_doc: bool) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_in_doc);
|
||||
}
|
||||
load_script(self);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,9 +71,12 @@ impl VirtualMethods for HTMLTitleElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, is_in_doc: bool) {
|
||||
fn bind_to_tree(&self, tree_in_doc: bool) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_in_doc);
|
||||
}
|
||||
let node = self.upcast::<Node>();
|
||||
if is_in_doc {
|
||||
if tree_in_doc {
|
||||
node.owner_doc().title_changed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1084,6 +1084,7 @@ impl Window {
|
|||
window_size: window_size,
|
||||
script_join_chan: join_chan,
|
||||
query_type: query_type,
|
||||
dom_count: self.Document().dom_count(),
|
||||
};
|
||||
|
||||
self.layout_chan.send(Msg::Reflow(reflow)).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue