summaryrefslogtreecommitdiffstats
path: root/config.def.h
diff options
context:
space:
mode:
authorMahouShoujoMivutilde <14999778+MahouShoujoMivutilde@users.noreply.github.com>2022-01-01 09:55:59 +0100
committerGitHub <noreply@github.com>2022-01-01 09:55:59 +0100
commite777adf98534394ca005a1ca541696b06c791aa6 (patch)
treeca62045ac14db93ff173c2b31a47edc34cba568d /config.def.h
parent1a691d42f6893e7bd6d18d541a9a46d87223c9cc (diff)
downloadnsxiv-e777adf98534394ca005a1ca541696b06c791aa6.tar.zst
Allow setting cache size based on memory percentage (#184)
The problem: 1. For the most people imlib2's default 4MiB is unreasonably low; 2. Hardcoding cache size to ~256MiB has performance benefits and doesn't increase RAM usage too much on relatively modern systems; 3. But we can't do that, because that would be detrimental to low spec systems that (apparently) not (?) building nsxiv from source, as been discussed #171 Solution: Calculate cache size based on total memory. Default is set as 3%, which means: * ~245MiB for 8GiB * ~30MiB for 1GiB * and so on CACHE_SIZE_LIMIT (256MiB by default) sets the highest possible value. And in case we cannot determine the total memory (e.g since _SC_PHYS_PAGES isn't POSIX) use CACHE_SIZE_FALLBACK (32MiB by default) instead. Co-authored-by: NRK <nrk@disroot.org>
Diffstat (limited to 'config.def.h')
-rw-r--r--config.def.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/config.def.h b/config.def.h
index 107c6ac..6e4b942 100644
--- a/config.def.h
+++ b/config.def.h
@@ -62,11 +62,14 @@ static const bool ANTI_ALIAS = true;
*/
static const bool ALPHA_LAYER = false;
-/* cache size for imlib2, in bytes. For backwards compatibility reasons, the
- * size is kept at 4MiB. For most users, it is advised to pick a value close to
- * or above 128MiB for better image (re)loading performance.
+/* percentage of memory to use for imlib2's cache size.
+ * 3 means use 3% of total memory which is about 245MiB on 8GiB machine.
+ * 0 or less means disable cache.
+ * 100 means use all available memory (but not above CACHE_SIZE_LIMIT).
*/
-static const int CACHE_SIZE = 4 * 1024 * 1024; /* 4MiB */
+static const int CACHE_SIZE_MEM_PERCENTAGE = 3; /* use 3% of total memory for cache */
+static const int CACHE_SIZE_LIMIT = 256 * 1024 * 1024; /* but not above 256MiB */
+static const int CACHE_SIZE_FALLBACK = 32 * 1024 * 1024; /* fallback to 32MiB if we can't determine total memory */
#endif
#ifdef _THUMBS_CONFIG