Blog
Tech5 min read

Go 1.24 Recap: Faster Maps, Honest Benchmarks

Maps become Swiss Tables, b.Loop() fixes benchmarks, tools move into go.mod, and os.Root blocks path traversal. Go 1.24 in five minutes.

#golang #go-recap #performance

Go recap series — one short post per release. Released February 2025.

TL;DR

  • Built-in map is now a Swiss Table — about 2–3% less CPU on average.
  • for b.Loop() replaces for range b.N in benchmarks.
  • Dev tools are tracked in go.mod with go get -tool.
  • os.Root keeps file access inside one directory.
  • Generic type aliases, omitzero, weak pointers, post-quantum crypto.

1. Maps are Swiss Tables

What changed: the built-in map was rewritten. Together with runtime tweaks, the Go team measured 2–3% less CPU overhead on average.

How it works: slots are grouped by 8. Each group has a small control word with a short fingerprint of each key. A lookup checks all 8 fingerprints at once and only compares the keys that match.

Why it matters: free speed. Just upgrade.

2. b.Loop() for benchmarks

go
func BenchmarkParse(b *testing.B) {
    input := loadFixture() // runs once
    for b.Loop() {
        Parse(input)
    }
}

Why it matters: setup runs once, and the compiler can't optimize away the code you are measuring. Your numbers are more honest.

3. Tools live in go.mod

text
$ go get -tool golang.org/x/tools/cmd/stringer
$ go tool stringer -type=Color

Why it matters: no more tools.go with blank imports. go install tool installs them all.

4. os.Root stops path traversal

go
root, err := os.OpenRoot("/srv/uploads")
if err != nil {
    return err
}
f, err := root.Open(name) // cannot escape /srv/uploads

Why it matters: if users send you file names, this is the easiest security fix you'll ship.

5. Small but useful

  • Generic type aliases: type Set[T comparable] = map[T]struct{}.
  • omitzero JSON tag: skips zero values — including a zero time.Time, which omitempty can't.
  • runtime.AddCleanup replaces SetFinalizer, and the weak package adds weak pointers for caches.
  • Post-quantum crypto: crypto/mlkem, and TLS uses X25519MLKEM768 by default.

Previous: ← Go 1.23 Recap · Next: Go 1.25 Recap →

Source: Go 1.24 release notes

Share To Friends