From 6f1ed65de90c387c3e38867b592c8fa7c8cfa80a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 22 Dec 2024 16:07:43 -0500 Subject: [PATCH] Tweak table resizing policy --- stdlib/tables.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/tables.c b/stdlib/tables.c index 38e98cc..ac8bebc 100644 --- a/stdlib/tables.c +++ b/stdlib/tables.c @@ -231,7 +231,7 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const int64_t key_size = type->TableInfo.key->size, value_size = type->TableInfo.value->size; if (!t->bucket_info || t->bucket_info->count == 0) { - hashmap_resize_buckets(t, 4, type); + hashmap_resize_buckets(t, 8, type); } else { // Check if we are clobbering a value: void *value_home = Table$get_raw(*t, key, type); @@ -251,7 +251,8 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const // Resize buckets if necessary if (t->entries.length >= (int64_t)t->bucket_info->count) { - uint32_t newsize = (uint32_t)t->bucket_info->count + MIN((uint32_t)t->bucket_info->count, 64); + // Current resize policy: +50% at a time: + uint32_t newsize = (3*(uint32_t)t->bucket_info->count)/2; if (unlikely(newsize > TABLE_MAX_BUCKETS)) newsize = t->entries.length + 1; hashmap_resize_buckets(t, newsize, type);