Overhaul ComputedValues measurement, and add style structs measurement.

This commit is contained in:
Nicholas Nethercote 2017-08-14 10:49:48 +10:00
parent 60c44b072c
commit 1a40101d2f
4 changed files with 77 additions and 44 deletions

View file

@ -16,7 +16,7 @@ use shared_lock::StylesheetGuards;
use std::fmt;
use std::ops::{Deref, DerefMut};
#[cfg(feature = "gecko")]
use stylesheets::{MallocSizeOfWithRepeats, SizeOfState};
use stylesheets::SizeOfState;
bitflags! {
flags RestyleFlags: u8 {
@ -261,6 +261,17 @@ impl ElementStyles {
pub fn is_display_none(&self) -> bool {
self.primary().get_box().clone_display() == display::T::none
}
#[cfg(feature = "gecko")]
fn malloc_size_of_children_excluding_cvs(&self, _state: &mut SizeOfState) -> usize {
// As the method name suggests, we don't measures the ComputedValues
// here, because they are measured on the C++ side.
// XXX: measure the EagerPseudoArray itself, but not the ComputedValues
// within it.
0
}
}
// We manually implement Debug for ElementStyles so that we can avoid the
@ -273,20 +284,6 @@ impl fmt::Debug for ElementStyles {
}
}
#[cfg(feature = "gecko")]
impl MallocSizeOfWithRepeats for ElementStyles {
fn malloc_size_of_children(&self, state: &mut SizeOfState) -> usize {
let mut n = 0;
if let Some(ref primary) = self.primary {
n += primary.malloc_size_of_children(state)
};
// We may measure more fields in the future if DMD says it's worth it.
n
}
}
/// Style system data associated with an Element.
///
/// In Gecko, this hangs directly off the Element. Servo, this is embedded
@ -436,12 +433,11 @@ impl ElementData {
pub fn clear_restyle_flags_and_damage(&mut self) {
self.restyle.clear_restyle_flags_and_damage();
}
}
#[cfg(feature = "gecko")]
impl MallocSizeOfWithRepeats for ElementData {
fn malloc_size_of_children(&self, state: &mut SizeOfState) -> usize {
let n = self.styles.malloc_size_of_children(state);
/// Measures memory usage.
#[cfg(feature = "gecko")]
pub fn malloc_size_of_children_excluding_cvs(&self, state: &mut SizeOfState) -> usize {
let n = self.styles.malloc_size_of_children_excluding_cvs(state);
// We may measure more fields in the future if DMD says it's worth it.

View file

@ -1915,11 +1915,26 @@ extern "C" {
pub fn Servo_Element_ClearData(node: RawGeckoElementBorrowed);
}
extern "C" {
pub fn Servo_Element_SizeOfExcludingThis(arg1: MallocSizeOf,
seen_ptrs: *mut SeenPtrs,
node: RawGeckoElementBorrowed)
pub fn Servo_Element_SizeOfExcludingThisAndCVs(malloc_size_of: MallocSizeOf,
seen_ptrs: *mut SeenPtrs,
node: RawGeckoElementBorrowed)
-> usize;
}
extern "C" {
pub fn Servo_Element_HasPrimaryComputedValues(element: RawGeckoElementBorrowed) -> bool;
}
extern "C" {
pub fn Servo_Element_GetPrimaryComputedValues(element: RawGeckoElementBorrowed)
-> ServoStyleContextStrong;
}
extern "C" {
pub fn Servo_Element_HasPseudoComputedValues(element: RawGeckoElementBorrowed, index: usize)
-> bool;
}
extern "C" {
pub fn Servo_Element_GetPseudoComputedValues(element: RawGeckoElementBorrowed, index: usize)
-> ServoStyleContextStrong;
}
extern "C" {
pub fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
gecko_stylesheet:

View file

@ -60,7 +60,6 @@ use selector_parser::PseudoElement;
use servo_arc::{Arc, RawOffsetArc};
use std::mem::{forget, uninitialized, transmute, zeroed};
use std::{cmp, ops, ptr};
use stylesheets::{MallocSizeOfWithRepeats, SizeOfState};
use values::{self, Auto, CustomIdent, Either, KeyframesName};
use values::computed::{NonNegativeAu, ToComputedValue, Percentage};
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
@ -369,18 +368,6 @@ impl ComputedValuesInner {
}
}
impl MallocSizeOfWithRepeats for ComputedValues {
fn malloc_size_of_children(&self, state: &mut SizeOfState) -> usize {
let mut n = 0;
if let Some(ref raw_offset_arc) = *self.get_raw_visited_style() {
n += raw_offset_arc.with_arc(|a: &Arc<ComputedValues>| {
a.malloc_size_of_children(state)
})
}
n
}
}
<%def name="declare_style_struct(style_struct)">
pub use ::gecko_bindings::structs::mozilla::Gecko${style_struct.gecko_name} as ${style_struct.gecko_struct_name};
impl ${style_struct.gecko_struct_name} {