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/dicache.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'src/dicache.c') 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; +} -- cgit v1.2.3