Shard your locks: benchmarking 6 Go cache designs
Benchmarked across 1-8 cores with 1M keys on a pinned i7-14700K, a 256-shard striped map (sharded) achieves 6.9x scaling with per-shard mutexes in about 15 lines of code, outperforming a single sync.Mutex by up to 8x. sync.RWMutex plateaus at 2x scaling and is slower for writes, while sync.Map shows great slope but poor absolute throughput. Copy-on-write delivers 87 Mops/s lock-free reads but zero writes due to copying the entire map per set—value size is irrelevant because Go strings are immutable.