December 20, 2025
Swiss tables, spicy takes
Hash tables in Go and advantage of self-hosted compilers
Go devs feud over “sets”: AI fibs, memory myths, and a compiler plot twist
TLDR: Switching Go maps from bool to an empty struct no longer saves memory thanks to Go 1.24’s new map design and alignment rules. Commenters roasted AI for stale advice, fought over readability vs idiomatic Set patterns, and called the compiler angle a distraction—proof that tech changes fast and myths die slowly.
Go doesn’t have a built-in Set, so devs fake it with a map. The classic trick: store keys with “nothing” as the value (an empty struct) to save memory. This post tried that switch from bool to empty struct and… nothing changed. Cue the drama. The culprit? Go 1.24’s shiny new “Swiss Table” map implementation plus alignment rules that pad that “nothing” into still-something. Translation: your zero-value hack no longer saves memory, and people have feelings about it.
The thread lit up fast. Hendrikto went full scorched earth on chatbots: don’t trust anything they say, period. Meanwhile, cabirum defended the empty struct as the idiomatic way to write a Set—readability complaints be damned—because if memory optimizations come back, your code’s already ready. pdpi called the “self-hosted compiler” angle a red herring, saying you don’t need insider status to read standard library code. nickcw even speculated whether the compiler really needs that 1-byte placeholder at all.
Memes arrived on time: devs joked that Swiss Tables turned Go maps into IKEA furniture—beautiful, compact, and somehow still missing a tiny screw. Others called empty struct values “ghost roommates”: they don’t pay rent but still take up space. For the curious, check the Go 1.24 release notes and the Swiss Table explanation on the official Go blog for the sober version. For everyone else, the comments are the show: AI skepticism, set-style purity wars, and a title that some say promised more than it delivered.
Key Points
- •Under Go 1.24’s Swiss Tables, map[int]struct{} does not reduce memory compared to map[int]bool.
- •Swiss Tables stores slots with key (8 bytes) and elem; zero-sized elem is treated as 1 byte and aligned, adding padding.
- •Alignment rules (via unsafe.Alignof) cause 7 bytes of padding, making per-slot size similar for bool and struct{} values.
- •Prior to Go 1.24, the bmap layout packed keys and values, eliminating padding; empty struct could then save memory.
- •Reading Go’s self-hosted compiler and runtime source clarified the map layout and explained the observed memory behavior.