mirror of
https://github.com/servo/servo.git
synced 2025-07-14 10:53:42 +01:00
Add STYLO_THREADS environment variable to control number of style worker threads.
This commit is contained in:
parent
fd09035c65
commit
00fe12d3ad
2 changed files with 21 additions and 3 deletions
|
@ -9,6 +9,7 @@ use num_cpus;
|
||||||
use selector_impl::{Animation, SharedStyleContext, Stylist, Stylesheet};
|
use selector_impl::{Animation, SharedStyleContext, Stylist, Stylesheet};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::env;
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use style::dom::OpaqueNode;
|
use style::dom::OpaqueNode;
|
||||||
|
@ -36,6 +37,17 @@ pub struct PerDocumentStyleData {
|
||||||
|
|
||||||
// FIXME(bholley): This shouldn't be per-document.
|
// FIXME(bholley): This shouldn't be per-document.
|
||||||
pub work_queue: WorkQueue<SharedStyleContext, WorkQueueData>,
|
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 {
|
impl PerDocumentStyleData {
|
||||||
|
@ -45,7 +57,6 @@ impl PerDocumentStyleData {
|
||||||
let device = Device::new(MediaType::Screen, window_size);
|
let device = Device::new(MediaType::Screen, window_size);
|
||||||
|
|
||||||
let (new_anims_sender, new_anims_receiver) = channel();
|
let (new_anims_sender, new_anims_receiver) = channel();
|
||||||
let num_threads = cmp::max(num_cpus::get() * 3 / 4, 1);
|
|
||||||
|
|
||||||
PerDocumentStyleData {
|
PerDocumentStyleData {
|
||||||
stylist: Arc::new(Stylist::new(device)),
|
stylist: Arc::new(Stylist::new(device)),
|
||||||
|
@ -55,7 +66,8 @@ impl PerDocumentStyleData {
|
||||||
new_animations_receiver: new_anims_receiver,
|
new_animations_receiver: new_anims_receiver,
|
||||||
running_animations: Arc::new(RwLock::new(HashMap::new())),
|
running_animations: Arc::new(RwLock::new(HashMap::new())),
|
||||||
expired_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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ use style::parallel;
|
||||||
use style::parser::ParserContextExtraData;
|
use style::parser::ParserContextExtraData;
|
||||||
use style::properties::{ComputedValues, PropertyDeclarationBlock};
|
use style::properties::{ComputedValues, PropertyDeclarationBlock};
|
||||||
use style::selector_impl::{SelectorImplExt, PseudoElementCascadeType};
|
use style::selector_impl::{SelectorImplExt, PseudoElementCascadeType};
|
||||||
|
use style::sequential;
|
||||||
use style::stylesheets::Origin;
|
use style::stylesheets::Origin;
|
||||||
use traversal::RecalcStyleOnly;
|
use traversal::RecalcStyleOnly;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -109,7 +110,12 @@ fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if node.is_dirty() || node.has_dirty_descendants() {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue