|
|
|
|
|
by jasonwatkinspdx
914 days ago
|
|
The api doc there says why but not fully in depth: > 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. sync#Map works by having two maps internally, one which receives writes and then periodically copies its values to the larger map and clears itself. This works on the two workloads mentioned above. It falls rather flat under write contention. This is by design. syncMap is really intended for maps that are mostly read only. |
|