Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
servo: Merge #17612 - Make the style statistics dump threshold config…
Browse files Browse the repository at this point in the history
…urable (from bholley:custom_threshold); r=emilio

I've wanted to change the threshold a couple of times, and adding in a
10-minute opt rebuild cycle is always a bit de-motivating.

I'm making this option gecko-only because it's pretty niche, and adding
support in servo would require threading it through all the options
stuff. We can add support for it there if we ever need it.

Source-Repo: https://github.com/servo/servo
Source-Revision: 340d350894584a413815fb2c62c88a9bde4e1dc5
  • Loading branch information
bholley committed Jul 6, 2017
1 parent 6629a88 commit acf8237
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions servo/components/style/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,30 @@ pub struct StyleSystemOptions {
pub disable_style_sharing_cache: bool,
/// Whether we should dump statistics about the style system.
pub dump_style_statistics: bool,
/// The minimum number of elements that must be traversed to trigger a dump
/// of style statistics.
pub style_statistics_threshold: usize,
}

#[cfg(feature = "gecko")]
fn get_env(name: &str) -> bool {
fn get_env_bool(name: &str) -> bool {
use std::env;
match env::var(name) {
Ok(s) => !s.is_empty(),
Err(_) => false,
}
}

const DEFAULT_STATISTICS_THRESHOLD: usize = 50;

#[cfg(feature = "gecko")]
fn get_env_usize(name: &str) -> Option<usize> {
use std::env;
env::var(name).ok().map(|s| {
s.parse::<usize>().expect("Couldn't parse environmental variable as usize")
})
}

impl Default for StyleSystemOptions {
#[cfg(feature = "servo")]
fn default() -> Self {
Expand All @@ -80,14 +93,17 @@ impl Default for StyleSystemOptions {
StyleSystemOptions {
disable_style_sharing_cache: opts::get().disable_share_style_cache,
dump_style_statistics: opts::get().style_sharing_stats,
style_statistics_threshold: DEFAULT_STATISTICS_THRESHOLD,
}
}

#[cfg(feature = "gecko")]
fn default() -> Self {
StyleSystemOptions {
disable_style_sharing_cache: get_env("DISABLE_STYLE_SHARING_CACHE"),
dump_style_statistics: get_env("DUMP_STYLE_STATISTICS"),
disable_style_sharing_cache: get_env_bool("DISABLE_STYLE_SHARING_CACHE"),
dump_style_statistics: get_env_bool("DUMP_STYLE_STATISTICS"),
style_statistics_threshold: get_env_usize("STYLE_STATISTICS_THRESHOLD")
.unwrap_or(DEFAULT_STATISTICS_THRESHOLD),
}
}
}
Expand Down Expand Up @@ -615,6 +631,8 @@ pub struct TraversalStatistics {
pub traversal_time_ms: f64,
/// Whether this was a parallel traversal.
pub is_parallel: Option<bool>,
/// Whether this is a "large" traversal.
pub is_large: Option<bool>,
}

/// Implementation of Add to aggregate statistics across different threads.
Expand All @@ -640,6 +658,7 @@ impl<'a> Add for &'a TraversalStatistics {
stylist_rebuilds: 0,
traversal_time_ms: 0.0,
is_parallel: None,
is_large: None,
}
}
}
Expand Down Expand Up @@ -675,7 +694,10 @@ impl TraversalStatistics {
where E: TElement,
D: DomTraversal<E>,
{
let threshold = traversal.shared_context().options.style_statistics_threshold;

self.is_parallel = Some(traversal.is_parallel());
self.is_large = Some(self.elements_traversed as usize >= threshold);
self.traversal_time_ms = (time::precise_time_s() - start) * 1000.0;
self.selectors = traversal.shared_context().stylist.num_selectors() as u32;
self.revalidation_selectors = traversal.shared_context().stylist.num_revalidation_selectors() as u32;
Expand All @@ -688,7 +710,7 @@ impl TraversalStatistics {
/// Returns whether this traversal is 'large' in order to avoid console spam
/// from lots of tiny traversals.
pub fn is_large_traversal(&self) -> bool {
self.elements_traversed >= 50
self.is_large.unwrap()
}
}

Expand Down

0 comments on commit acf8237

Please sign in to comment.