From 1a885c25f7ad7eb217d9b2f0ab477ab1b7be6433 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 3 Aug 2025 15:02:41 +0200 Subject: Add about:dicache for decompressed image cache The dicache holds the decompressed buffers for each image and it often is the main cause for memory consumption in Dillo. The current algorithm for evicting entries waits until a image has no references and at least three pages were opened before removing the entry. --- src/cache.c | 2 ++ src/dicache.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/dicache.h | 14 ++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/cache.c b/src/cache.c index 7ee9d9d7..5a852167 100644 --- a/src/cache.c +++ b/src/cache.c @@ -427,6 +427,8 @@ static int Cache_internal_url(CacheEntry_t *entry) if (strcmp(URL_PATH(entry->Url), "cache") == 0) { s = Cache_stats(); + } else if (strcmp(URL_PATH(entry->Url), "dicache") == 0) { + s = a_Dicache_stats(); } if (s != NULL) { diff --git a/src/dicache.c b/src/dicache.c index e53fb011..e83d2d72 100644 --- a/src/dicache.c +++ b/src/dicache.c @@ -2,7 +2,7 @@ * File: dicache.c * * Copyright 2000-2007 Jorge Arellano Cid - * Copyright 2024 Rodrigo Arias Mallo + * Copyright 2024-2025 Rodrigo Arias Mallo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -191,6 +191,14 @@ static void Dicache_remove(const DilloUrl *Url, int version) dFree(entry); } +static int Dicache_is_last_ref(DICacheEntry *entry) +{ + if (entry->v_imgbuf) + return a_Imgbuf_last_reference(entry->v_imgbuf); + + return 0; +} + /** * Unrefs the counter of a dicache entry (it counts cache clients). * If there're no clients and no imgbuf, remove the entry. @@ -599,3 +607,49 @@ void a_Dicache_freeall(void) } dList_free(CachedIMGs); } + +Dstr *a_Dicache_stats(void) +{ + long bytesCached = 0L; + Dstr *s = dStr_new( + "\n" + "\n" + "Decompressed Image Cache\n" + "\n"); + + int n = dList_length(CachedIMGs); + dStr_sprintfa(s, "

Decompressed Image Cache (%d)

\n", n); + + dStr_append(s, "\n"); + dStr_append(s, "\n"); + dStr_append(s, "\n"); + dStr_append(s, "\n"); + dStr_append(s, "\n"); + dStr_append(s, "\n"); + dStr_append(s, "\n"); + dStr_append(s, "\n"); + for (int i = 0; i < n; i++) { + DICacheEntry *e = dList_nth_data(CachedIMGs, i); + dStr_append(s, "\n"); + dStr_sprintfa(s, "", e->SurvCleanup); + dStr_sprintfa(s, "", Dicache_is_last_ref(e)); + dStr_sprintfa(s, "", e->width, e->height); + dStr_sprintfa(s, "\n", + e->TotalSize / 1024.0f); + dStr_sprintfa(s, "\n"); + dStr_append(s, "\n"); + bytesCached += (long) e->TotalSize; + } + dStr_append(s, "
SLAreaSizeURL
%hd%d%ux%u%.2f KiB", URL_STR(e->url)); + dStr_shorten(s, URL_STR(e->url), 60); + dStr_append(s, "
\n"); + float mb = (float) bytesCached / (1024.0f * 1024.0f); + + dStr_sprintfa(s, "

Total cached: %.2f MiB

\n", mb); + + dStr_append(s, + "\n" + "\n"); + + return s; +} diff --git a/src/dicache.h b/src/dicache.h index e0f49dfb..815dcf6a 100644 --- a/src/dicache.h +++ b/src/dicache.h @@ -1,3 +1,15 @@ +/* + * File: dicache.c + * + * Copyright 2000-2007 Jorge Arellano Cid + * Copyright 2025 Rodrigo Arias Mallo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + */ + #ifndef __DICACHE_H__ #define __DICACHE_H__ @@ -9,6 +21,7 @@ extern "C" { #include "bitvec.h" #include "image.hh" #include "cache.h" +#include "dlib/dlib.h" /** Symbolic name to request the last version of an image */ #define DIC_Last -1 @@ -76,6 +89,7 @@ DICacheEntry* a_Dicache_ref(const DilloUrl *Url, int version); void a_Dicache_unref(const DilloUrl *Url, int version); void a_Dicache_cleanup(void); void a_Dicache_freeall(void); +Dstr *a_Dicache_stats(void); #ifdef __cplusplus -- cgit v1.2.3