How Swiss Tables Work in Go’s Built-in Map

10 points by func25


MaskRay

Go's map uses tombstone values, which isn't ideal, but it has little choice. Its iteration semantics forbid relocating live entries. The small/large split costs Go code footprint too, but only once - whole implementation is one copy in the runtime (about 23KiB in a binary my agent measured).

C++ has no equivalent: template monomorphizes per type, so a second representation is duplicated across every instantiation. In a clang binary, llvm::DenseMapBase::moveFrom is instantiated 1949 times (833KiB). I'm wary of adding per-instantiation code here. In LLVM, none of the hash table uses Swiss Table: https://maskray.me/blog/2026-06-07-recent-llvm-hash-table-improvements