Compare versioned map implementations
Compare versioned map implementations
Go maps expose key lookup, insertion, deletion and iteration, not their storage layout. Go 1.23 runtime/map.go uses buckets containing up to eight entries, short hash fragments and overflow buckets; growth gradually evacuates old buckets. Go 1.24 introduced a Swiss Table-based implementation: groups contain slots and control bytes carrying occupancy and hash fragments, with probing and a directory of tables that can grow or split. The new design changes lookup and growth mechanics, not the language contract. These descriptions are version-specific; the local toolchain is Go 1.23.2.
package main
import ( "fmt")
func main() { m := make(map[int]int, 2) for i := 0; i < 1000; i++ { m[i] = i * i } delete(m, 5) v, ok := m[5] fmt.Println(len(m), m[999], v, ok)}The capacity argument is a hint, not a maximum. Inserting many keys may cause growth, but this program does not observe the number of buckets, groups or allocations. A missing key yields the zero value; comma-ok distinguishes absence from a stored zero. Iteration order is unspecified, and concurrent writes require synchronization.
Expected output:
999 998001 0 falseHash fragments are filters, not equality
package main
import ( "fmt" "sort")
func fragment(h uint64) uint64 { return h & 127 }func main() { a, b := uint64(7), uint64(135) fmt.Println(fragment(a) == fragment(b), a == b) m := map[string]int{"b": 2, "a": 1} keys := make([]string, 0, len(m)) for k := range m { keys = append(keys, k) } sort.Strings(keys) fmt.Println(keys)}This artificial seven-bit fragment demonstrates a collision, not Go runtime hashing. A candidate still requires key equality. Sorting keys makes presentation deterministic without relying on internal traversal. Swiss Table details are verified against the Go 1.24 release notes and engineering article; no Go 1.24 binary or speed comparison was run here. Never infer a speedup for your workload from the design alone.
Expected output:
true false[a b]Try it locally
Insert 2,048 integer keys into a map with hint 1, remove all even keys, sum remaining values (each value equals its key), and print count and sum. Do not rely on iteration order.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Runtime representations 02: Compare versioned map implementations
Check the lesson objective before moving on.
Which property survives the Go 1.24 map redesign?
Why must a candidate matching a short hash fragment still be compared?