[gtk/wip/chergert/glproto: 503/526] use move-to-front semantics for glyph cache




commit a40a0cd60c9bd8ecd586b64201e42339f4591fd3
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 10 17:16:40 2021 -0800

    use move-to-front semantics for glyph cache
    
    this just keys off the glyph id (LSB) for a quick move-to-front avoiding
    accessing the hashtable altogether. since we usually access things of a
    similar type, this gets the hashtable costs mostly off the profiles from
    the text nodes.

 gsk/next/gskglglyphlibraryprivate.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/gsk/next/gskglglyphlibraryprivate.h b/gsk/next/gskglglyphlibraryprivate.h
index d95001c5ff..78fa7a370b 100644
--- a/gsk/next/gskglglyphlibraryprivate.h
+++ b/gsk/next/gskglglyphlibraryprivate.h
@@ -58,6 +58,10 @@ struct _GskGLGlyphLibrary
   GHashTable          *hash_table;
   guint8              *surface_data;
   gsize                surface_data_len;
+  struct {
+    GskGLGlyphKey key;
+    const GskGLGlyphValue *value;
+  } front[256];
 };
 
 GskGLGlyphLibrary *gsk_gl_glyph_library_new (GskNextDriver          *driver);
@@ -88,10 +92,17 @@ gsk_gl_glyph_library_lookup_or_add (GskGLGlyphLibrary      *self,
                                     const GskGLGlyphValue **out_value)
 {
   GskGLTextureAtlasEntry *entry;
+  guint front_index = key->glyph & 0xFF;
 
-  if G_LIKELY (gsk_gl_texture_library_lookup ((GskGLTextureLibrary *)self, key, &entry))
+  if (memcmp (key, &self->front[front_index], sizeof *key) == 0)
+    {
+      *out_value = self->front[front_index].value;
+    }
+  else if (gsk_gl_texture_library_lookup ((GskGLTextureLibrary *)self, key, &entry))
     {
       *out_value = (GskGLGlyphValue *)entry;
+      self->front[front_index].key = *key;
+      self->front[front_index].value = *out_value;
     }
   else
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]