Bug 1518045 - Make Servo use a single thread-pool for layout-related tasks per-process. r=jdm

Instead of per-document. This also allows to reuse this thread-pool if needed
for other stuff, like parallel CSS parsing (#22478), and to share more code with
Gecko, which is always nice.

This cherry-picks https://github.com/servo/servo/pull/22487, with a few minor
fixes to the build that are landing as part of the sync associated to this bug,
and an lsan exception tweak to point to the right module since it's moving.
This commit is contained in:
Emilio Cobos Álvarez 2018-12-17 23:46:42 +01:00
Родитель 6c649bdee4
Коммит 1834c20f36
8 изменённых файлов: 35 добавлений и 22 удалений

Просмотреть файл

@ -27,7 +27,7 @@ leak:GI___strdup
leak:PR_Sleep
# Bug 1363976 - Stylo holds some global data alive forever.
leak:style::gecko::global_style_data
leak:style::global_style_data
###
### Many leaks only affect some test suites. The suite annotations are not checked.

Просмотреть файл

@ -16,8 +16,7 @@ path = "lib.rs"
doctest = false
[features]
gecko = ["nsstring", "num_cpus",
"style_traits/gecko", "fallible/known_system_malloc"]
gecko = ["nsstring", "style_traits/gecko", "fallible/known_system_malloc"]
use_bindgen = ["bindgen", "regex", "toml"]
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
"cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union",
@ -48,7 +47,7 @@ malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
matches = "0.1"
nsstring = {path = "../../../xpcom/rust/nsstring/", optional = true}
num_cpus = {version = "1.1.0", optional = true}
num_cpus = {version = "1.1.0"}
num-integer = "0.1"
num-traits = "0.2"
num-derive = "0.2"

Просмотреть файл

@ -10,7 +10,6 @@ mod non_ts_pseudo_class_list;
pub mod arc_types;
pub mod conversions;
pub mod data;
pub mod global_style_data;
pub mod media_features;
pub mod media_queries;
pub mod pseudo_element;

Просмотреть файл

@ -24,7 +24,6 @@ use crate::dom::{LayoutIterator, NodeInfo, OpaqueNode, TDocument, TElement, TNod
use crate::element_state::{DocumentState, ElementState};
use crate::font_metrics::{FontMetrics, FontMetricsProvider, FontMetricsQueryResult};
use crate::gecko::data::GeckoStyleSheet;
use crate::gecko::global_style_data::GLOBAL_STYLE_DATA;
use crate::gecko::selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl};
use crate::gecko::snapshot_helpers;
use crate::gecko_bindings::bindings;
@ -59,6 +58,7 @@ use crate::gecko_bindings::structs::NODE_NEEDS_FRAME;
use crate::gecko_bindings::structs::{nsAtom, nsIContent, nsINode_BooleanFlag};
use crate::gecko_bindings::structs::{RawGeckoElement, RawGeckoNode, RawGeckoXBLBinding};
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
use crate::global_style_data::GLOBAL_STYLE_DATA;
use crate::hash::FxHashMap;
use crate::logical_geometry::WritingMode;
use crate::media_queries::Device;

Просмотреть файл

@ -5,15 +5,13 @@
//! Global style data
use crate::context::StyleSystemOptions;
#[cfg(feature = "gecko")]
use crate::gecko_bindings::bindings;
use crate::parallel::STYLE_THREAD_STACK_SIZE_KB;
use crate::shared_lock::SharedRwLock;
use crate::thread_state;
use num_cpus;
use rayon;
use std::cmp;
use std::env;
use std::ffi::CString;
/// Global style data
pub struct GlobalStyleData {
@ -37,20 +35,22 @@ fn thread_name(index: usize) -> String {
format!("StyleThread#{}", index)
}
fn thread_startup(index: usize) {
fn thread_startup(_index: usize) {
thread_state::initialize_layout_worker_thread();
#[cfg(feature = "gecko")]
unsafe {
use std::ffi::CString;
bindings::Gecko_SetJemallocThreadLocalArena(true);
}
let name = thread_name(index);
let name = CString::new(name).unwrap();
unsafe {
let name = thread_name(_index);
let name = CString::new(name).unwrap();
// Gecko_RegisterProfilerThread copies the passed name here.
bindings::Gecko_RegisterProfilerThread(name.as_ptr());
}
}
fn thread_shutdown(_: usize) {
#[cfg(feature = "gecko")]
unsafe {
bindings::Gecko_UnregisterProfilerThread();
bindings::Gecko_SetJemallocThreadLocalArena(false);
@ -64,12 +64,26 @@ lazy_static! {
.map(|s| s.parse::<usize>().expect("invalid STYLO_THREADS value"));
let mut num_threads = match stylo_threads {
Ok(num) => num,
// The default heuristic is num_virtual_cores * .75. This gives us
// three threads on a hyper-threaded dual core, and six threads on
// a hyper-threaded quad core. The performance benefit of additional
// threads seems to level off at around six, so we cap it there on
// many-core machines (see bug 1431285 comment 14).
_ => cmp::min(cmp::max(num_cpus::get() * 3 / 4, 1), 6),
#[cfg(feature = "servo")]
_ => {
// We always set this pref on startup, before layout or script
// have had a chance of accessing (and thus creating) the
// thread-pool.
use servo_config::prefs::PREFS;
PREFS.get("layout.threads").as_u64().unwrap() as usize
}
#[cfg(feature = "gecko")]
_ => {
// The default heuristic is num_virtual_cores * .75. This gives
// us three threads on a hyper-threaded dual core, and six
// threads on a hyper-threaded quad core. The performance
// benefit of additional threads seems to level off at around
// six, so we cap it there on many-core machines
// (see bug 1431285 comment 14).
use num_cpus;
use std::cmp;
cmp::min(cmp::max(num_cpus::get() * 3 / 4, 1), 6)
}
};
// If num_threads is one, there's no point in creating a thread pool, so

Просмотреть файл

@ -133,6 +133,7 @@ pub mod font_metrics;
#[cfg(feature = "gecko")]
#[allow(unsafe_code)]
pub mod gecko_bindings;
pub mod global_style_data;
pub mod hash;
pub mod invalidation;
#[allow(missing_docs)] // TODO.

Просмотреть файл

@ -30,7 +30,6 @@ use style::element_state::{DocumentState, ElementState};
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
use style::font_metrics::{get_metrics_provider_for_product, FontMetricsProvider};
use style::gecko::data::{GeckoStyleSheet, PerDocumentStyleData, PerDocumentStyleDataImpl};
use style::gecko::global_style_data::{GlobalStyleData, GLOBAL_STYLE_DATA, STYLE_THREAD_POOL};
use style::gecko::restyle_damage::GeckoRestyleDamage;
use style::gecko::selector_parser::{NonTSPseudoClass, PseudoElement};
use style::gecko::traversal::RecalcStyleOnly;
@ -168,6 +167,7 @@ use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasFFI};
use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
use style::gecko_bindings::sugar::refptr::RefPtr;
use style::gecko_properties;
use style::global_style_data::{GlobalStyleData, GLOBAL_STYLE_DATA, STYLE_THREAD_POOL};
use style::invalidation::element::restyle_hints;
use style::media_queries::MediaList;
use style::parser::{self, Parse, ParserContext};

Просмотреть файл

@ -7,7 +7,7 @@ use nsstring::nsCString;
use servo_arc::Arc;
use style::context::QuirksMode;
use style::gecko::data::GeckoStyleSheet;
use style::gecko::global_style_data::GLOBAL_STYLE_DATA;
use style::global_style_data::GLOBAL_STYLE_DATA;
use style::gecko_bindings::bindings;
use style::gecko_bindings::bindings::Gecko_LoadStyleSheet;
use style::gecko_bindings::structs::{Loader, LoaderReusableStyleSheets};