Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
1 / 5
0

unique.Make in Go 1.23: String Interning Without sync.Pool Tricks

DEV Community·Gabriel Anhaia·25 days ago
#pH0q605O
#when#go#performance#string#unique#handle
Reading 0:00
15s threshold

Book: The Complete Guide to Go Programming Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub You take a heap profile of a metrics-heavy Go service and the largest object on the heap is a map[string]*Series with millions of entries. Each key is something like http_requests_total{method="GET",route="/users/:id",status="200"} . The map is hundreds of megabytes, most of it duplicate keys. The runtime has been holding the same "GET" string in memory a few hundred thousand times because every label-set assembly path went through fmt.Sprintf or strings.Join and produced a fresh allocation. This is the workload unique was added for in Go 1.23. The package solves one problem: give equal values one shared backing copy so the heap stops carrying duplicates. On the right workload it cuts memory by ~10x.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More