net: Report memory usage for image cache. (#36556)

These changes add a new report for image cache memory usage for each
script thread.

Testing: Looked at the numbers after browsing various stock photo sites
that show galleries of images.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-04-16 09:11:51 -04:00 committed by GitHub
parent f16f625c9b
commit afe98e9e1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 49 additions and 7 deletions

View file

@ -10,6 +10,7 @@ use ipc_channel::ipc::IpcSender;
use log::debug;
use malloc_size_of_derive::MallocSizeOf;
use pixels::{Image, ImageMetadata};
use profile_traits::mem::Report;
use serde::{Deserialize, Serialize};
use servo_url::{ImmutableOrigin, ServoUrl};
@ -36,7 +37,7 @@ pub enum ImageOrMetadataAvailable {
/// and image, and returned to the specified event loop when the
/// image load completes. It is typically used to trigger a reflow
/// and/or repaint.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct ImageResponder {
pipeline_id: PipelineId,
pub id: PendingImageId,
@ -73,11 +74,11 @@ impl ImageResponder {
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub enum ImageResponse {
/// The requested image was loaded.
Loaded(#[ignore_malloc_size_of = "Arc"] Arc<Image>, ServoUrl),
Loaded(#[conditional_malloc_size_of] Arc<Image>, ServoUrl),
/// The request image metadata was loaded.
MetadataLoaded(ImageMetadata),
/// The requested image failed to load, so a placeholder was loaded instead.
PlaceholderLoaded(#[ignore_malloc_size_of = "Arc"] Arc<Image>, ServoUrl),
PlaceholderLoaded(#[conditional_malloc_size_of] Arc<Image>, ServoUrl),
/// Neither the requested image nor the placeholder could be loaded.
None,
}
@ -115,6 +116,8 @@ pub trait ImageCache: Sync + Send {
where
Self: Sized;
fn memory_report(&self, prefix: &str) -> Report;
/// Definitively check whether there is a cached, fully loaded image available.
fn get_image(
&self,