Performance Optimizations in Go 1.24: Swiss Table Maps and More
Go 1.24 introduces significant performance optimizations, particularly in the way maps are handled. One of the standout features is the…
Go 1.24 introduces significant performance optimizations, particularly in the way maps are handled. One of the standout features is the…
Performance Optimizations in Go 1.24: Swiss Table Maps and More
Go 1.24 introduces significant performance optimizations, particularly in the way maps are handled. One of the standout features is the introduction of Swiss Table-based maps, which improve lookup and insertion performance. Additionally, Go 1.24 brings several other runtime and memory optimizations that make Go applications faster and more efficient.
Swiss Table Maps: A Game-Changer
What Are Swiss Tables?
Swiss Tables are a modern hash table implementation that optimizes memory layout and lookup performance by reducing collisions and improving cache locality. Originally introduced by Google for high-performance applications, this approach now powers Go’s built-in map implementation.
Performance Gains
Swiss Tables in Go 1.24 provide:
- Faster lookups: Optimized probing reduces the number of cache misses.
- Better memory efficiency: More compact storage leads to reduced memory footprint.
- Improved insertions and deletions: Less overhead when modifying maps.
Benchmarking Swiss Tables
Let’s compare the old vs. new map performance using Go’s benchmarking framework.
package main
import (
"fmt"
"io"
"testing"
)
func BenchmarkMapInsert(b *testing.B) {
m := make(map[int]int)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m[i] = i
}
}
func BenchmarkMapLookup(b *testing.B) {
m := make(map[int]int)
for i := 0; i < 1_000_000; i++ {
m[i] = i
}
var n int
b.ResetTimer()
for i := 0; i < b.N; i++ {
n = m[i%1_000_000]
}
_, _ = fmt.Fprintln(io.Discard, n)
}Benchmarks comparing Go 1.23 and Go 1.24 on an Apple M1 Pro show significant performance improvements:
Execution Time (sec/op)
| Benchmark | Go 1.23 | Go 1.24 (RC2) | Improvement |
|---|---|---|---|
| MapInsert-10 | 137.10n ± 4% | 93.70n ± 2% | -31.65% |
| MapLookup-10 | 41.17n ± 2% | 32.36n ± 5% | -21.40% |
These benchmarks confirm that Swiss Table maps in Go 1.24 lead to significant reductions in execution time while maintaining similar memory and allocation efficiency.
Runtime and Memory Optimizations
1. Improved Garbage Collection (GC)
Go 1.24 optimizes how GC manages memory allocation for small objects, reducing GC pauses and improving overall application responsiveness.
2. New Internal Mutex Implementation
A refined mutex implementation improves contention resolution, leading to better concurrency performance, especially in applications with high lock contention.
3. Enhanced sync.Map Performance
Modifications to sync.Map make disjoint key accesses significantly faster, reducing contention in concurrent workloads.
How to Enable/Disable Swiss Table Maps
By default, Swiss Table maps are enabled in Go 1.24, but developers can opt out using:
GOEXPERIMENT=noswissmap go buildConclusion
Swiss Table maps and runtime optimizations in Go 1.24 lead to measurable performance improvements, making Go applications faster and more memory-efficient.
Stay tuned for the next post, where we explore the new os.Root type and its implications for secure filesystem access.