Skip to content

Commit 929ded6

Browse files
committed
eagerly truncate table on delete if table becomes too sparse
1 parent d75c179 commit 929ded6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

grumpy-runtime-src/runtime/dict.go

+9
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,15 @@ func (d *Dict) putItem(f *Frame, key, value *Object, overwrite bool) (*Object, *
536536
if overwrite {
537537
t.writeValue(entry, value)
538538
d.incVersion()
539+
if value == nil && t.used < t.capa/8 && t.fill > t.capa/8*5 {
540+
if newTable, ok := t.growTable(); ok {
541+
d.storeTable(newTable)
542+
// doesn't increment version here, because we didn't change content in growTable.
543+
} else {
544+
d.mutex.Unlock(f)
545+
panic("some unknown error on downsizing dictionary")
546+
}
547+
}
539548
}
540549
}
541550
d.mutex.Unlock(f)

0 commit comments

Comments
 (0)