Skip to content

Commit

Permalink
Optimizing hashtable.grow() for faster hashtables (#459)
Browse files Browse the repository at this point in the history
* Using a specialized version of Insert to speed up hashmap expansion

* Further improvements

* undo changes and update TODO
  • Loading branch information
SamWheating authored Mar 2, 2023
1 parent dded032 commit 4b1e35f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions starlark/hashtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,12 @@ func overloaded(elems, buckets int) bool {

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

0 comments on commit 4b1e35f

Please sign in to comment.