summaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-11-25 13:44:21 -0500
committerAndras Timar <andras.timar@collabora.com>2018-03-20 12:26:20 +0100
commit0f3f1bfe679977cbbfffa8f86270d1ef3da77922 (patch)
treefec45c8d0d759e0cc7a928e33f61afe153657b2e /external
parent1a85bef5cba39f7bd0100c8f43ee3d80e0bbd37c (diff)
pixman: drop cached glyphs above size watermark
The glyphs cache only tracked the number of glyphs in the cache, which isn't very useful when the glyphs vary in size from a few bytes to dozens of megabytes. In terms of memory footprint, we are interested not just in the number of cached glyphs, but also in the total memory usage. We now track the pixel-size of each glyph and drop as many as necessary to fall below the set threshold which is currently 4 MBs. There was no performance loss observed after this patch on a diverse set of documents of all types (if anything, a very modest performance win was hinted in some cases), with significant memory reduction in some cases where dozens of megabytes were previously left stale in the cache. Change-Id: I377a4c1e59611fca6bf253dd9fa90f75b5295d4b Reviewed-on: https://gerrit.libreoffice.org/45378 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com> (cherry picked from commit 407660a08c8df27d7cd44435eefa31bd92364a3c) (cherry picked from commit ded39dc17a34127a872b11abddc32bbbb5aae047) Reviewed-on: https://gerrit.libreoffice.org/46987 Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit c8176326324aef63ddc29eafd1193f2abba80c92)
Diffstat (limited to 'external')
-rw-r--r--external/cairo/pixman/pixman-0.24.4.patch72
1 files changed, 71 insertions, 1 deletions
diff --git a/external/cairo/pixman/pixman-0.24.4.patch b/external/cairo/pixman/pixman-0.24.4.patch
index 520f2ba572d4..6d871e37bfd1 100644
--- a/external/cairo/pixman/pixman-0.24.4.patch
+++ b/external/cairo/pixman/pixman-0.24.4.patch
@@ -18,4 +18,74 @@
+#include <limits.h>
#include "pixman-private.h"
-
+
+--- misc/pixman-0.24.4/pixman/pixman-glyph.c 2015-06-30 05:48:31.000000000 -0400
++++ misc/build/pixman-0.24.4/pixman/pixman-glyph.c 2017-11-25 13:26:33.075558418 -0500
+@@ -38,6 +38,7 @@
+
+ /* XXX: These numbers are arbitrary---we've never done any measurements.
+ */
++#define N_PIXELS_HIGH_WATER (4 * 1024 * 1024)
+ #define N_GLYPHS_HIGH_WATER (16384)
+ #define N_GLYPHS_LOW_WATER (8192)
+ #define HASH_SIZE (2 * N_GLYPHS_HIGH_WATER)
+@@ -58,6 +59,7 @@
+ int n_glyphs;
+ int n_tombstones;
+ int freeze_count;
++ long n_pixels;
+ pixman_list_t mru;
+ glyph_t * glyphs[HASH_SIZE];
+ };
+@@ -133,6 +135,7 @@
+ if (*loc == TOMBSTONE)
+ cache->n_tombstones--;
+ cache->n_glyphs++;
++ cache->n_pixels += glyph->image->bits.width * glyph->image->bits.height;
+
+ *loc = glyph;
+ }
+@@ -150,6 +153,7 @@
+ cache->glyphs[idx & HASH_MASK] = TOMBSTONE;
+ cache->n_tombstones++;
+ cache->n_glyphs--;
++ cache->n_pixels -= glyph->image->bits.width * glyph->image->bits.height;
+
+ /* Eliminate tombstones if possible */
+ if (cache->glyphs[(idx + 1) & HASH_MASK] == NULL)
+@@ -180,6 +184,7 @@
+
+ cache->n_glyphs = 0;
+ cache->n_tombstones = 0;
++ cache->n_pixels = 0;
+ }
+
+ PIXMAN_EXPORT pixman_glyph_cache_t *
+@@ -194,6 +199,7 @@
+ cache->n_glyphs = 0;
+ cache->n_tombstones = 0;
+ cache->freeze_count = 0;
++ cache->n_pixels = 0;
+
+ pixman_list_init (&cache->mru);
+
+@@ -220,9 +226,9 @@
+ pixman_glyph_cache_thaw (pixman_glyph_cache_t *cache)
+ {
+ if (--cache->freeze_count == 0 &&
+- cache->n_glyphs + cache->n_tombstones > N_GLYPHS_HIGH_WATER)
++ (cache->n_glyphs + cache->n_tombstones > N_GLYPHS_HIGH_WATER || cache->n_pixels > N_PIXELS_HIGH_WATER))
+ {
+- if (cache->n_tombstones > N_GLYPHS_HIGH_WATER)
++ if (cache->n_tombstones > N_GLYPHS_LOW_WATER)
+ {
+ /* More than half the entries are
+ * tombstones. Just dump the whole table.
+@@ -230,7 +236,7 @@
+ clear_table (cache);
+ }
+
+- while (cache->n_glyphs > N_GLYPHS_LOW_WATER)
++ while (cache->n_glyphs > N_GLYPHS_LOW_WATER || cache->n_pixels > N_PIXELS_HIGH_WATER)
+ {
+ glyph_t *glyph = CONTAINER_OF (glyph_t, mru_link, cache->mru.tail);