mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #15535 - froydnj:global-style-thread-pool, r=bholley
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 may be obvious to an experienced Rust programmer, but I went with raw pointers because trying to use `Option` global variables resulted in complaints about turning on feature flags in nightly Rust. Since this is for stylo, nightly features are not appropriate here. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15535) <!-- Reviewable:end -->
This commit is contained in:
commit
56a99577b3
9 changed files with 60 additions and 47 deletions
|
@ -13,7 +13,7 @@ path = "lib.rs"
|
|||
doctest = false
|
||||
|
||||
[features]
|
||||
gecko = ["nsstring_vendor", "num_cpus", "rayon/unstable"]
|
||||
gecko = ["nsstring_vendor", "rayon/unstable"]
|
||||
use_bindgen = ["bindgen", "regex"]
|
||||
servo = ["serde/unstable", "serde", "serde_derive", "heapsize_derive",
|
||||
"style_traits/servo", "servo_atoms", "html5ever-atoms",
|
||||
|
@ -57,10 +57,6 @@ servo_url = {path = "../url"}
|
|||
time = "0.1"
|
||||
unicode-segmentation = "1.0"
|
||||
|
||||
[dependencies.num_cpus]
|
||||
optional = true
|
||||
version = "1.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
kernel32-sys = "0.2"
|
||||
|
||||
|
|
|
@ -11,13 +11,9 @@ use gecko_bindings::bindings::RawServoStyleSet;
|
|||
use gecko_bindings::structs::RawGeckoPresContextOwned;
|
||||
use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
||||
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;
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||
use stylesheets::Stylesheet;
|
||||
|
@ -48,29 +44,12 @@ 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
|
||||
/// and unexpected races while trying to mutate it.
|
||||
pub struct PerDocumentStyleData(AtomicRefCell<PerDocumentStyleDataImpl>);
|
||||
|
||||
lazy_static! {
|
||||
/// The number of layout threads, computed statically.
|
||||
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 {
|
||||
/// Create a dummy `PerDocumentStyleData`.
|
||||
pub fn new(pres_context: RawGeckoPresContextOwned) -> Self {
|
||||
|
@ -86,14 +65,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 +112,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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,6 @@ extern crate matches;
|
|||
#[cfg(feature = "gecko")] extern crate nsstring_vendor as nsstring;
|
||||
extern crate num_integer;
|
||||
extern crate num_traits;
|
||||
#[cfg(feature = "gecko")] extern crate num_cpus;
|
||||
extern crate ordered_float;
|
||||
extern crate owning_ref;
|
||||
extern crate parking_lot;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue