Skip to content

Commit

Permalink
Measure ImageValue objects.
Browse files Browse the repository at this point in the history
We have about 11,500 of these when loading gmail in a Stylo-enabled build, from
SpecifiedUrls; the objects themselves account for about 1.3 MiB of memory, and
the strings within them about 2.9 MiB.

We also have a very small number of them on the Gecko side.
  • Loading branch information
nnethercote committed Sep 14, 2017
1 parent 49f7535 commit a185393
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions components/style/gecko/generated/bindings.rs
Expand Up @@ -1000,6 +1000,10 @@ extern "C" {
extern "C" {
pub fn Gecko_ImageValue_Create(aURI: ServoBundledURI) -> *mut ImageValue;
}
extern "C" {
pub fn Gecko_ImageValue_SizeOfIncludingThis(aImageValue: *mut ImageValue)
-> usize;
}
extern "C" {
pub fn Gecko_SetLayerImageImageValue(image: *mut nsStyleImage,
aImageValue: *mut ImageValue);
Expand Down
28 changes: 24 additions & 4 deletions components/style/gecko/url.rs
Expand Up @@ -9,28 +9,26 @@ use gecko_bindings::structs::mozilla::css::URLValueData;
use gecko_bindings::structs::root::mozilla::css::ImageValue;
use gecko_bindings::structs::root::nsStyleImageRequest;
use gecko_bindings::sugar::refptr::RefPtr;
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use parser::ParserContext;
use servo_arc::Arc;
use std::fmt;
use style_traits::{ToCss, ParseError};

/// A specified url() value for gecko. Gecko does not eagerly resolve SpecifiedUrls.
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct SpecifiedUrl {
/// The URL in unresolved string form.
///
/// Refcounted since cloning this should be cheap and data: uris can be
/// really large.
#[ignore_malloc_size_of = "XXX: do this once bug 1397971 lands"]
serialization: Arc<String>,

/// The URL extra data.
#[ignore_malloc_size_of = "RefPtr is tricky, and there aren't many of these in practise"]
pub extra_data: RefPtr<URLExtraData>,

/// Cache ImageValue, if any, so that we can reuse it while rematching a
/// a property with this specified url value.
#[ignore_malloc_size_of = "XXX: do this once bug 1397971 lands"]
pub image_value: Option<RefPtr<ImageValue>>,
}
trivial_to_computed_value!(SpecifiedUrl);
Expand Down Expand Up @@ -133,3 +131,25 @@ impl ToCss for SpecifiedUrl {
dest.write_str(")")
}
}

impl MallocSizeOf for SpecifiedUrl {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
use gecko_bindings::bindings::Gecko_ImageValue_SizeOfIncludingThis;

let mut n = 0;

// XXX: measure `serialization` once bug 1397971 lands

// We ignore `extra_data`, because RefPtr is tricky, and there aren't
// many of them in practise (sharing is common).

if let Some(ref image_value) = self.image_value {
// Although this is a RefPtr, this is the primary reference because
// SpecifiedUrl is responsible for creating the image_value. So we
// measure unconditionally here.
n += unsafe { Gecko_ImageValue_SizeOfIncludingThis(image_value.clone().get()) };
}

n
}
}

0 comments on commit a185393

Please sign in to comment.