Skip to content

Commit

Permalink
Add STYLO_THREADS environment variable to control number of style wor…
Browse files Browse the repository at this point in the history
…ker threads.
  • Loading branch information
heycam authored and bholley committed Jul 6, 2016
1 parent fd09035 commit 00fe12d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 14 additions & 2 deletions ports/geckolib/data.rs
Expand Up @@ -9,6 +9,7 @@ use num_cpus;
use selector_impl::{Animation, SharedStyleContext, Stylist, Stylesheet};
use std::cmp;
use std::collections::HashMap;
use std::env;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::{Arc, RwLock};
use style::dom::OpaqueNode;
Expand Down Expand Up @@ -36,6 +37,17 @@ pub struct PerDocumentStyleData {

// FIXME(bholley): This shouldn't be per-document.
pub work_queue: WorkQueue<SharedStyleContext, WorkQueueData>,

pub num_threads: usize,
}

lazy_static! {
pub static ref NUM_THREADS: usize = {
match env::var("STYLO_THREADS").map(|s| s.parse::<usize>().expect("invalid STYLO_THREADS")) {
Ok(num) => num,
_ => cmp::max(num_cpus::get() * 3 / 4, 1),
}
};
}

impl PerDocumentStyleData {
Expand All @@ -45,7 +57,6 @@ impl PerDocumentStyleData {
let device = Device::new(MediaType::Screen, window_size);

let (new_anims_sender, new_anims_receiver) = channel();
let num_threads = cmp::max(num_cpus::get() * 3 / 4, 1);

PerDocumentStyleData {
stylist: Arc::new(Stylist::new(device)),
Expand All @@ -55,7 +66,8 @@ impl PerDocumentStyleData {
new_animations_receiver: new_anims_receiver,
running_animations: Arc::new(RwLock::new(HashMap::new())),
expired_animations: Arc::new(RwLock::new(HashMap::new())),
work_queue: WorkQueue::new("StyleWorker", thread_state::LAYOUT, num_threads),
work_queue: WorkQueue::new("StyleWorker", thread_state::LAYOUT, *NUM_THREADS),
num_threads: *NUM_THREADS,
}
}

Expand Down
8 changes: 7 additions & 1 deletion ports/geckolib/glue.rs
Expand Up @@ -29,6 +29,7 @@ use style::parallel;
use style::parser::ParserContextExtraData;
use style::properties::{ComputedValues, PropertyDeclarationBlock};
use style::selector_impl::{SelectorImplExt, PseudoElementCascadeType};
use style::sequential;
use style::stylesheets::Origin;
use traversal::RecalcStyleOnly;
use url::Url;
Expand Down Expand Up @@ -109,7 +110,12 @@ fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
};

if node.is_dirty() || node.has_dirty_descendants() {
parallel::traverse_dom::<GeckoNode, RecalcStyleOnly>(node, &shared_style_context, &mut per_doc_data.work_queue);
if per_doc_data.num_threads == 1 {
sequential::traverse_dom::<GeckoNode, RecalcStyleOnly>(node, &shared_style_context);
} else {
parallel::traverse_dom::<GeckoNode, RecalcStyleOnly>(node, &shared_style_context,
&mut per_doc_data.work_queue);
}
}
}

Expand Down

0 comments on commit 00fe12d

Please sign in to comment.