[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/hash-table-perf 0c413df4fae 2/2: Change default size to 0 (from
From: |
Mattias Engdegård |
Subject: |
scratch/hash-table-perf 0c413df4fae 2/2: Change default size to 0 (from 6) |
Date: |
Tue, 9 Jan 2024 08:50:34 -0500 (EST) |
branch: scratch/hash-table-perf
commit 0c413df4fae4dddc4ab0cc83f8309aaa8473236c
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Change default size to 0 (from 6)
We effectively postpone hash table allocations to the first
insertion (unless make-hash-table was called with a positive :size),
which is a clear gain as long as the table remains empty.
* src/lisp.h (DEFAULT_HASH_SIZE): Change to 0 (from 6).
* src/fns.c (maybe_resize_hash_table): Grow from 0 to 6.
---
src/fns.c | 6 ++++--
src/lisp.h | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/fns.c b/src/fns.c
index 09ab59a453c..7b360b4b1fe 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4668,8 +4668,10 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
ptrdiff_t old_size = HASH_TABLE_SIZE (h);
ptrdiff_t base_size = min (max (old_size, 6), PTRDIFF_MAX / 2);
/* Grow aggressively at small sizes, then just double. */
- ptrdiff_t new_size = (base_size <= 64 ? base_size * 4
- : base_size * 2);
+ ptrdiff_t new_size =
+ old_size == 0
+ ? 6
+ : (base_size <= 64 ? base_size * 4 : base_size * 2);
/* Allocate all the new vectors before updating *H, to
avoid problems if memory is exhausted. */
diff --git a/src/lisp.h b/src/lisp.h
index 032747a1afb..c596e4b9767 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2593,7 +2593,7 @@ void hash_table_thaw (Lisp_Object hash_table);
/* Default size for hash tables if not specified. */
-enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 6 };
+enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 0 };
/* Combine two integers X and Y for hashing. The result might exceed
INTMASK. */