mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Stop storing depth per-node in the sequential traversal.
This has two advantages: * It allows us to store nodes in the same format that the parallel traversal uses. * It allows us to double the size of the sequential work queue without increasing the storage, which allows us to have WORK_UNIT_MAX * 2 entries before heap- allocating, which is about what we want for adaptive mode. MozReview-Commit-ID: 6VQwGfTQgct
This commit is contained in:
parent
7fa6e35583
commit
2908b52c7b
1 changed files with 16 additions and 10 deletions
|
@ -7,13 +7,12 @@
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
use context::{StyleContext, ThreadLocalStyleContext};
|
use context::{StyleContext, ThreadLocalStyleContext};
|
||||||
use dom::{TElement, TNode};
|
use dom::{SendNode, TElement, TNode};
|
||||||
|
use parallel::WORK_UNIT_MAX;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use time;
|
use time;
|
||||||
use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
|
use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
|
||||||
|
|
||||||
struct WorkItem<N: TNode>(N, usize);
|
|
||||||
|
|
||||||
/// Do a sequential DOM traversal for layout or styling, generic over `D`.
|
/// Do a sequential DOM traversal for layout or styling, generic over `D`.
|
||||||
pub fn traverse_dom<E, D>(traversal: &D,
|
pub fn traverse_dom<E, D>(traversal: &D,
|
||||||
root: E,
|
root: E,
|
||||||
|
@ -27,29 +26,36 @@ pub fn traverse_dom<E, D>(traversal: &D,
|
||||||
debug_assert!(!traversal.is_parallel());
|
debug_assert!(!traversal.is_parallel());
|
||||||
debug_assert!(token.should_traverse());
|
debug_assert!(token.should_traverse());
|
||||||
|
|
||||||
let mut discovered = VecDeque::<WorkItem<E::ConcreteNode>>::with_capacity(16);
|
let mut discovered =
|
||||||
|
VecDeque::<SendNode<E::ConcreteNode>>::with_capacity(WORK_UNIT_MAX * 2);
|
||||||
let mut tlc = ThreadLocalStyleContext::new(traversal.shared_context());
|
let mut tlc = ThreadLocalStyleContext::new(traversal.shared_context());
|
||||||
let mut context = StyleContext {
|
let mut context = StyleContext {
|
||||||
shared: traversal.shared_context(),
|
shared: traversal.shared_context(),
|
||||||
thread_local: &mut tlc,
|
thread_local: &mut tlc,
|
||||||
};
|
};
|
||||||
|
|
||||||
let root_depth = root.depth();
|
|
||||||
discovered.push_back(WorkItem(root.as_node(), root_depth));
|
|
||||||
|
|
||||||
// Process the nodes breadth-first, just like the parallel traversal does.
|
// Process the nodes breadth-first, just like the parallel traversal does.
|
||||||
// This helps keep similar traversal characteristics for the style sharing
|
// This helps keep similar traversal characteristics for the style sharing
|
||||||
// cache.
|
// cache.
|
||||||
while let Some(WorkItem(node, depth)) = discovered.pop_front() {
|
let mut depth = root.depth();
|
||||||
|
let mut nodes_remaining_at_current_depth = 1;
|
||||||
|
discovered.push_back(unsafe { SendNode::new(root.as_node()) });
|
||||||
|
while let Some(node) = discovered.pop_front() {
|
||||||
let mut children_to_process = 0isize;
|
let mut children_to_process = 0isize;
|
||||||
let traversal_data = PerLevelTraversalData { current_dom_depth: depth };
|
let traversal_data = PerLevelTraversalData { current_dom_depth: depth };
|
||||||
traversal.process_preorder(&traversal_data, &mut context, node, |n| {
|
traversal.process_preorder(&traversal_data, &mut context, *node, |n| {
|
||||||
children_to_process += 1;
|
children_to_process += 1;
|
||||||
discovered.push_back(WorkItem(n, depth + 1));
|
discovered.push_back(unsafe { SendNode::new(n) });
|
||||||
});
|
});
|
||||||
|
|
||||||
traversal.handle_postorder_traversal(&mut context, root.as_node().opaque(),
|
traversal.handle_postorder_traversal(&mut context, root.as_node().opaque(),
|
||||||
node, children_to_process);
|
*node, children_to_process);
|
||||||
|
nodes_remaining_at_current_depth -= 1;
|
||||||
|
if nodes_remaining_at_current_depth == 0 {
|
||||||
|
depth += 1;
|
||||||
|
nodes_remaining_at_current_depth = discovered.len();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump statistics to stdout if requested.
|
// Dump statistics to stdout if requested.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue