Skip to content

Commit 4b1e35f

Browse files
authored
Optimizing hashtable.grow() for faster hashtables (#459)
* Using a specialized version of Insert to speed up hashmap expansion * Further improvements * undo changes and update TODO
1 parent dded032 commit 4b1e35f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

starlark/hashtable.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,12 @@ func overloaded(elems, buckets int) bool {
155155

156156
func (ht *hashtable) grow() {
157157
// Double the number of buckets and rehash.
158-
// TODO(adonovan): opt:
159-
// - avoid reentrant calls to ht.insert, and specialize it.
160-
// e.g. we know the calls to Equals will return false since
161-
// there are no duplicates among the old keys.
162-
// - saving the entire hash in the bucket would avoid the need to
163-
// recompute the hash.
164-
// - save the old buckets on a free list.
158+
//
159+
// Even though this makes reentrant calls to ht.insert,
160+
// calls Equals unnecessarily (since there can't be duplicate keys),
161+
// and recomputes the hash unnecessarily, the gains from
162+
// avoiding these steps were found to be too small to justify
163+
// the extra logic: -2% on hashtable benchmark.
165164
ht.table = make([]bucket, len(ht.table)<<1)
166165
oldhead := ht.head
167166
ht.head = nil

0 commit comments

Comments
 (0)