3 ms·
Sync.map is meant to have poor performance I believe https://github.com/golang/go/issues/21031 https://github.com/golang/go/issues/21031
by strangelove026 2y ago
Sync.map is meant to have poor performance I believe
https://github.com/golang/go/issues/21031 https://github.com/golang/go/issues/21031
- PhilippGille 2y agoIt depends on the use case. From the Godoc: > The Map type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex. Source: https://pkg.go.dev/sync#Map https://pkg.go.dev/sync#Map And regarding slow writes, those were recently improved in Go 1.24: > The implementation of sync.Map has been changed, improving performance, particularly for map modifications. For instance, modifications of disjoint sets of keys are much less likely to contend on larger maps, and there is no longer any ramp-up time required to achieve low-contention loads from the map. Source: https://go.dev/doc/go1.24#minor_library_changes https://go.dev/doc/go1.24#minor_library_changes ("sync" section)