mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
geckolib: use a global thread pool for styling
By having a single thread pool, rather than one per document, we use less memory. This addresses https://bugzilla.mozilla.org/show_bug.cgi?id=1324250.
This commit is contained in:
parent
469ed934e7
commit
3e81f8431e
5 changed files with 22 additions and 25 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -906,6 +906,7 @@ dependencies = [
|
|||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"selectors 0.18.0",
|
||||
"servo_url 0.0.1",
|
||||
"style 0.0.1",
|
||||
|
|
|
@ -14,7 +14,6 @@ use media_queries::Device;
|
|||
use num_cpus;
|
||||
use parking_lot::RwLock;
|
||||
use properties::ComputedValues;
|
||||
use rayon;
|
||||
use std::cmp;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
|
@ -48,13 +47,6 @@ pub struct PerDocumentStyleDataImpl {
|
|||
/// Unused. Will go away when we actually implement transitions and
|
||||
/// animations properly.
|
||||
pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
|
||||
|
||||
/// The worker thread pool.
|
||||
/// FIXME(bholley): This shouldn't be per-document.
|
||||
pub work_queue: Option<rayon::ThreadPool>,
|
||||
|
||||
/// The number of threads of the work queue.
|
||||
pub num_threads: usize,
|
||||
}
|
||||
|
||||
/// The data itself is an `AtomicRefCell`, which guarantees the proper semantics
|
||||
|
@ -86,14 +78,6 @@ 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: if *NUM_THREADS <= 1 {
|
||||
None
|
||||
} else {
|
||||
let configuration =
|
||||
rayon::Configuration::new().set_num_threads(*NUM_THREADS);
|
||||
rayon::ThreadPool::new(configuration).ok()
|
||||
},
|
||||
num_threads: *NUM_THREADS,
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -141,9 +125,3 @@ unsafe impl HasFFI for PerDocumentStyleData {
|
|||
}
|
||||
unsafe impl HasSimpleFFI for PerDocumentStyleData {}
|
||||
unsafe impl HasBoxFFI for PerDocumentStyleData {}
|
||||
|
||||
impl Drop for PerDocumentStyleDataImpl {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.work_queue.take();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ libc = "0.2"
|
|||
log = {version = "0.3.5", features = ["release_max_level_info"]}
|
||||
num_cpus = "1.1.0"
|
||||
parking_lot = "0.3"
|
||||
rayon = "0.6"
|
||||
selectors = {path = "../../components/selectors"}
|
||||
servo_url = {path = "../../components/url"}
|
||||
style = {path = "../../components/style", features = ["gecko"]}
|
||||
|
|
|
@ -9,6 +9,7 @@ use cssparser::ToCss as ParserToCss;
|
|||
use env_logger::LogBuilder;
|
||||
use euclid::Size2D;
|
||||
use parking_lot::RwLock;
|
||||
use rayon;
|
||||
use selectors::Element;
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::Cow;
|
||||
|
@ -90,6 +91,20 @@ use stylesheet_loader::StylesheetLoader;
|
|||
* depend on but good enough for our purposes.
|
||||
*/
|
||||
|
||||
lazy_static! {
|
||||
static ref STYLE_THREAD_POOL: Option<rayon::ThreadPool> = {
|
||||
let num_threads = *NUM_THREADS;
|
||||
if num_threads <= 1 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let configuration =
|
||||
rayon::Configuration::new().set_num_threads(num_threads);
|
||||
let pool = rayon::ThreadPool::new(configuration).ok();
|
||||
pool
|
||||
};
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_Initialize() -> () {
|
||||
// Initialize logging.
|
||||
|
@ -148,7 +163,7 @@ fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed,
|
|||
}
|
||||
}
|
||||
|
||||
let mut per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
|
||||
let token = RecalcStyleOnly::pre_traverse(element, &per_doc_data.stylist, unstyled_children_only);
|
||||
if !token.should_traverse() {
|
||||
|
@ -159,7 +174,7 @@ fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed,
|
|||
debug!("{:?}", ShowSubtreeData(element.as_node()));
|
||||
|
||||
let shared_style_context = create_shared_context(&per_doc_data);
|
||||
let traversal_driver = if per_doc_data.num_threads == 1 || per_doc_data.work_queue.is_none() {
|
||||
let traversal_driver = if STYLE_THREAD_POOL.is_none() {
|
||||
TraversalDriver::Sequential
|
||||
} else {
|
||||
TraversalDriver::Parallel
|
||||
|
@ -169,7 +184,7 @@ fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed,
|
|||
let known_depth = None;
|
||||
if traversal_driver.is_parallel() {
|
||||
parallel::traverse_dom(&traversal, element, known_depth, token,
|
||||
per_doc_data.work_queue.as_mut().unwrap());
|
||||
STYLE_THREAD_POOL.as_ref().unwrap());
|
||||
} else {
|
||||
sequential::traverse_dom(&traversal, element, token);
|
||||
}
|
||||
|
|
|
@ -9,9 +9,11 @@ extern crate atomic_refcell;
|
|||
extern crate cssparser;
|
||||
extern crate env_logger;
|
||||
extern crate euclid;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
extern crate libc;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate parking_lot;
|
||||
extern crate rayon;
|
||||
extern crate selectors;
|
||||
extern crate servo_url;
|
||||
extern crate style;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue