From 8a0dd452d2d9141e68f2d5eb82475735adb7c861 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 29 Sep 2020 15:57:33 +0200 Subject: [PATCH 1/3] gdkarray: Inline splice and reserve This inlines the splice and reserver GdkArray calls. These are typically only called from the gdk_array_(append/set_size) functions anyway, and inlining the caller means we can constant propagate the constant arguments in those calls. Its hard to get exact numbers, but in fishbowl i noticed a significant decrease in the time spent in the array code when pushing and poping states. --- gdk/gdkarrayimpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdk/gdkarrayimpl.c b/gdk/gdkarrayimpl.c index 6692245aa7..65b74a3f59 100644 --- a/gdk/gdkarrayimpl.c +++ b/gdk/gdkarrayimpl.c @@ -141,7 +141,7 @@ gdk_array(is_empty) (const GdkArray *self) return self->end == self->start; } -G_GNUC_UNUSED static void +G_GNUC_UNUSED static inline void gdk_array(reserve) (GdkArray *self, gsize n) { @@ -178,7 +178,7 @@ gdk_array(reserve) (GdkArray *self, #endif } -G_GNUC_UNUSED static void +G_GNUC_UNUSED static inline void gdk_array(splice) (GdkArray *self, gsize pos, gsize removed, From 18b8b499de22907ad1177953fb8ef734c721b586 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 29 Sep 2020 16:00:30 +0200 Subject: [PATCH 2/3] gdkarray: Add support for GDK_ARRAY_NO_MEMSET If all your callers already initialize the array element as needed, then we don't need to memset it to zero first. This is pretty useful for the snapshot state stack, because due to the per-node-type data area the elements on the stack are quite large, but often a lot of it is not used. --- gdk/gdkarrayimpl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdk/gdkarrayimpl.c b/gdk/gdkarrayimpl.c index 65b74a3f59..003c67fd59 100644 --- a/gdk/gdkarrayimpl.c +++ b/gdk/gdkarrayimpl.c @@ -208,8 +208,10 @@ gdk_array(splice) (GdkArray *self, memcpy (gdk_array(index) (self, pos), additions, added * sizeof (_T_)); +#ifndef GDK_ARRAY_NO_MEMSET else memset (gdk_array(index) (self, pos), 0, added * sizeof (_T_)); +#endif } @@ -279,5 +281,5 @@ gdk_array(get) (const GdkArray *self, #undef GDK_ARRAY_NULL_TERMINATED #undef GDK_ARRAY_PREALLOC #undef GDK_ARRAY_TYPE_NAME - +#undef GDK_ARRAY_NO_MEMSET #endif From 796e6ee3062dc7d2eae5cb9a48f66a4e84b2992a Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 29 Sep 2020 16:03:06 +0200 Subject: [PATCH 3/3] snapshot: Preallocate and don't memset the state stack Most of the time the snapshot is less than 16 levels deep (did some testing in gtk-demo), so lets pre-allocate 16 levels of state stack to avoid the extra allocation most of the time. --- gtk/gtksnapshot.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index ab19aa8ac1..bca48076cd 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -132,6 +132,8 @@ static void gtk_snapshot_state_clear (GtkSnapshotState *state); #define GDK_ARRAY_ELEMENT_TYPE GtkSnapshotState #define GDK_ARRAY_FREE_FUNC gtk_snapshot_state_clear #define GDK_ARRAY_BY_VALUE 1 +#define GDK_ARRAY_PREALLOC 16 +#define GDK_ARRAY_NO_MEMSET 1 #include "gdk/gdkarrayimpl.c" /* This is a nasty little hack. We typedef GtkSnapshot to the fake object GdkSnapshot