From 3ead244914999049e48fb5f41b4420f97a61a984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 9 Aug 2025 23:23:01 -0400 Subject: [PATCH] util/set: start with 16 entries to reduce reallocations when growing the set The set originally started with just 2 entries. Reviewed-by: Gert Wollny Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/util/set.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util/set.c b/src/util/set.c index bddf59e2efb..1f6df96ad85 100644 --- a/src/util/set.c +++ b/src/util/set.c @@ -59,9 +59,24 @@ static const struct { { max_entries, size, rehash, \ REMAINDER_MAGIC(size), REMAINDER_MAGIC(rehash) } + /* Starting with only 2 entries at initialization causes a lot of set + * reallocations and rehashing while growing the set. + * + * Below are results from counting reallocations when compiling + * my GLSL shader-db on radeonsi+ACO. + * + * 2 entries is the baseline. + * Starting with 4 entries reduces reallocations to 55%. + * Starting with 8 entries reduces reallocations to 37%. + * Starting with 16 entries reduces reallocations to 28%. + * Starting with 32 entries reduces reallocations to 23%. + * Starting with 64 entries reduces reallocations to 21%. + */ +#if 0 /* Start with 16 entries. */ ENTRY(2, 5, 3 ), ENTRY(4, 7, 5 ), ENTRY(8, 13, 11 ), +#endif ENTRY(16, 19, 17 ), ENTRY(32, 43, 41 ), ENTRY(64, 73, 71 ),