Skip to content

Commit

Permalink
parallel selector matching
Browse files Browse the repository at this point in the history
  • Loading branch information
ILyoan committed Oct 31, 2013
1 parent 1a7e9e5 commit 901dfc4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
45 changes: 39 additions & 6 deletions src/components/main/css/matching.rs
Expand Up @@ -5,6 +5,12 @@
// High-level interface to CSS selector matching.

use std::cell::Cell;
use std::comm;
use std::rt::default_sched_threads;
use std::task;
use std::vec;
use extra::arc::RWArc;

use css::node_style::StyledNode;
use css::node_util::NodeUtil;
use layout::incremental;
Expand All @@ -16,7 +22,7 @@ use servo_util::tree::TreeNodeRef;

pub trait MatchMethods {
fn match_node(&self, stylist: &Stylist);
fn match_subtree(&self, stylist: &Stylist);
fn match_subtree(&self, stylist: RWArc<Stylist>);

fn cascade_node(&self, parent: Option<AbstractNode<LayoutView>>);
fn cascade_subtree(&self, parent: Option<AbstractNode<LayoutView>>);
Expand All @@ -36,14 +42,41 @@ impl MatchMethods for AbstractNode<LayoutView> {
data.applicable_declarations = cell.take();
}
}
fn match_subtree(&self, stylist: &Stylist) {
self.match_node(stylist);
fn match_subtree(&self, stylist: RWArc<Stylist>) {
let num_tasks = default_sched_threads() * 2;
let mut node_count = 0;
let mut nodes_per_task = vec::from_elem(num_tasks, ~[]);

for kid in self.children() {
if kid.is_element() {
kid.match_subtree(stylist);
for node in self.traverse_preorder() {
if node.is_element() {
nodes_per_task[node_count % num_tasks].push(node);
node_count += 1;
}
}

let (port, chan) = comm::stream();
let chan = comm::SharedChan::new(chan);
let mut num_spawned = 0;

for nodes in nodes_per_task.move_iter() {
if nodes.len() > 0 {
let chan = chan.clone();
let stylist = stylist.clone();
do task::spawn_with((nodes, stylist)) |(nodes, stylist)| {
let nodes = Cell::new(nodes);
do stylist.read |stylist| {
for node in nodes.take().move_iter() {
node.match_node(stylist);
}
}
chan.send(());
}
num_spawned += 1;
}
}
for _ in range(0, num_spawned) {
port.recv();
}
}

fn cascade_node(&self, parent: Option<AbstractNode<LayoutView>>) {
Expand Down
13 changes: 8 additions & 5 deletions src/components/main/layout/layout_task.rs
Expand Up @@ -20,7 +20,7 @@ use std::cast::transmute;
use std::cell::Cell;
use std::comm::{Port};
use std::task;
use extra::arc::Arc;
use extra::arc::{Arc, RWArc};
use geom::point::Point2D;
use geom::rect::Rect;
use geom::size::Size2D;
Expand Down Expand Up @@ -65,7 +65,7 @@ struct LayoutTask {

display_list: Option<Arc<DisplayList<AbstractNode<()>>>>,

stylist: Stylist,
stylist: RWArc<Stylist>,
profiler_chan: ProfilerChan,
}

Expand Down Expand Up @@ -240,7 +240,7 @@ impl LayoutTask {

display_list: None,

stylist: new_stylist(),
stylist: RWArc::new(new_stylist()),
profiler_chan: profiler_chan,
}
}
Expand Down Expand Up @@ -293,7 +293,10 @@ impl LayoutTask {
}

fn handle_add_stylesheet(&mut self, sheet: Stylesheet) {
self.stylist.add_stylesheet(sheet, AuthorOrigin);
let sheet = Cell::new(sheet);
do self.stylist.write |stylist| {
stylist.add_stylesheet(sheet.take(), AuthorOrigin)
}
}

/// The high-level routine that performs layout tasks.
Expand Down Expand Up @@ -335,7 +338,7 @@ impl LayoutTask {
ReflowDocumentDamage => {}
MatchSelectorsDocumentDamage => {
do profile(time::LayoutSelectorMatchCategory, self.profiler_chan.clone()) {
node.match_subtree(&self.stylist);
node.match_subtree(self.stylist.clone());
node.cascade_subtree(None);
}
}
Expand Down

13 comments on commit 901dfc4

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at ILyoan@901dfc4

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ILyoan/servo/parallel_selector_matching = 901dfc4 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ILyoan/servo/parallel_selector_matching = 901dfc4 merged ok, testing candidate = dbebe98

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at ILyoan@901dfc4

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ILyoan/servo/parallel_selector_matching = 901dfc4 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ILyoan/servo/parallel_selector_matching = 901dfc4 merged ok, testing candidate = b125601

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at ILyoan@901dfc4

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ILyoan/servo/parallel_selector_matching = 901dfc4 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ILyoan/servo/parallel_selector_matching = 901dfc4 merged ok, testing candidate = ddce8b8

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = ddce8b8

Please sign in to comment.