Skip to content

Commit

Permalink
Increase the size of the style sharing cache to 31.
Browse files Browse the repository at this point in the history
Still a lot of guesswork here, but this does seem to get us better sharing.  See
https://bugzilla.mozilla.org/show_bug.cgi?id=1369621 for some data.
  • Loading branch information
bzbarsky committed Jun 8, 2017
1 parent 93271e1 commit 2f2b93c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
16 changes: 2 additions & 14 deletions components/style/parallel.rs
Expand Up @@ -26,7 +26,6 @@ use context::TraversalStatistics;
use dom::{OpaqueNode, SendNode, TElement, TNode};
use rayon;
use scoped_tls::ScopedTLS;
use sharing::STYLE_SHARING_CANDIDATE_CACHE_SIZE;
use smallvec::SmallVec;
use std::borrow::Borrow;
use std::mem;
Expand All @@ -36,21 +35,10 @@ use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
/// The maximum number of child nodes that we will process as a single unit.
///
/// Larger values will increase style sharing cache hits and general DOM locality
/// at the expense of decreased opportunities for parallelism. The style sharing
/// cache can hold 8 entries, but not all styles are shareable, so we set this
/// value to 16. These values have not been measured and could potentially be
/// tuned.
/// at the expense of decreased opportunities for parallelism. This value has not
/// been measured and could potentially be tuned.
pub const WORK_UNIT_MAX: usize = 16;

/// Verify that the style sharing cache size doesn't change. If it does, we should
/// reconsider the above. We do this, rather than defining WORK_UNIT_MAX in terms
/// of STYLE_SHARING_CANDIDATE_CACHE_SIZE, so that altering the latter doesn't
/// have surprising effects on the parallelism characteristics of the style system.
#[allow(dead_code)]
fn static_assert() {
unsafe { mem::transmute::<_, [u32; STYLE_SHARING_CANDIDATE_CACHE_SIZE]>([1; 8]); }
}

/// A list of node pointers.
///
/// Note that the inline storage doesn't need to be sized to WORK_UNIT_MAX, but
Expand Down
12 changes: 10 additions & 2 deletions components/style/sharing/mod.rs
Expand Up @@ -84,8 +84,16 @@ use stylist::{ApplicableDeclarationBlock, Stylist};
mod checks;

/// The amount of nodes that the style sharing candidate cache should hold at
/// most.
pub const STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 8;
/// most. We'd somewhat like 32, but ArrayDeque only implements certain backing
/// store sizes. A cache size of 32 would mean a backing store of 33, but
/// that's not an implemented size: we can do 32 or 40.
///
/// The cache size was chosen by measuring style sharing and resulting
/// performance on a few pages; sizes up to about 32 were giving good sharing
/// improvements (e.g. 3x fewer styles having to be resolved than at size 8) and
/// slight performance improvements. Sizes larger than 32 haven't really been
/// tested.
pub const STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 31;

/// Controls whether the style sharing cache is used.
#[derive(Clone, Copy, PartialEq)]
Expand Down

0 comments on commit 2f2b93c

Please sign in to comment.