finds.dev← search

// the find

orcaman/concurrent-map

★ 4,531 · Go · MIT · updated May 2024

a thread-safe concurrent map for go

A sharded concurrent map for Go that splits the keyspace across 32 buckets to reduce lock contention. Predates sync.Map and still makes sense for write-heavy workloads where sync.Map's append-optimized design is a poor fit. Single file, no dependencies.

Sharding over a single RWMutex is the right call for write-heavy maps — sync.Map trades write performance for read performance, so this fills a real gap. Generics support (v2) means you get type safety without interface{} boxing. The implementation is small enough to read in 20 minutes and audit for correctness. MIT license, zero dependencies.

The shard count (32) is hardcoded and not tunable — if your key distribution is pathological or your CPU count is very high, you're stuck. No iteration order guarantees and the IterCb / Items approaches require grabbing all shard locks sequentially, which is a stop-the-world for large maps. Last meaningful activity was 2024 and Travis CI badge is broken, which suggests maintenance is on life support. The sharding key is FNV hash of the string key, so non-string keys require a custom hasher that the API doesn't make obvious.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →