go/src/sync
Changkun Ou 2e8dbae85c sync: add new Map method LoadAndDelete
This CL implements a LoadAndDelete method in sync.Map. Benchmark:

name                                              time/op
LoadAndDeleteBalanced/*sync_test.RWMutexMap-12    98.8ns ± 1%
LoadAndDeleteBalanced/*sync.Map-12                10.3ns ±11%
LoadAndDeleteUnique/*sync_test.RWMutexMap-12      99.2ns ± 2%
LoadAndDeleteUnique/*sync.Map-12                  6.63ns ±10%
LoadAndDeleteCollision/*sync_test.DeepCopyMap-12   140ns ± 0%
LoadAndDeleteCollision/*sync_test.RWMutexMap-12   75.2ns ± 2%
LoadAndDeleteCollision/*sync.Map-12               5.21ns ± 5%

In addition, Delete is bounded and more efficient if many collisions:

DeleteCollision/*sync_test.DeepCopyMap-12   120ns ± 2%   125ns ± 1%   +3.80%  (p=0.000 n=10+9)
DeleteCollision/*sync_test.RWMutexMap-12   73.5ns ± 3%  79.5ns ± 1%   +8.03%  (p=0.000 n=10+9)
DeleteCollision/*sync.Map-12               97.8ns ± 3%   5.9ns ± 4%  -94.00%  (p=0.000 n=10+10)

Fixes #33762

Change-Id: Ic8469a7861d27ab0edeface0078aad8af9b26c2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/205899
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-25 14:31:55 +00:00
..
atomic sync/atomic: suppress checkptr errors for hammerStoreLoadPointer 2019-10-22 18:09:03 +00:00
cond.go
cond_test.go
example_pool_test.go
example_test.go
export_test.go sync: fix pool wrap-around test 2019-06-26 19:48:39 +00:00
map.go sync: add new Map method LoadAndDelete 2020-02-25 14:31:55 +00:00
map_bench_test.go sync: add new Map method LoadAndDelete 2020-02-25 14:31:55 +00:00
map_reference_test.go sync: add new Map method LoadAndDelete 2020-02-25 14:31:55 +00:00
map_test.go sync: add new Map method LoadAndDelete 2020-02-25 14:31:55 +00:00
mutex.go sync: yield to the waiter when unlocking a starving mutex 2019-11-09 19:31:32 +00:00
mutex_test.go sync: allow inlining the Mutex.Unlock fast path 2019-03-05 14:59:31 +00:00
once.go sync: document implementation of Once.Do 2019-07-01 14:45:49 +00:00
once_test.go
pool.go sync: update comment 2019-04-19 16:15:36 +00:00
pool_test.go sync: only check for successful PopHeads in long mode 2019-06-26 19:48:42 +00:00
poolqueue.go sync: internal dynamically sized lock-free queue for sync.Pool 2019-04-05 18:49:04 +00:00
runtime.go sync: allow inlining the Mutex.Lock fast path 2019-03-09 05:08:04 +00:00
runtime_sema_test.go sync: allow inlining the Mutex.Unlock fast path 2019-03-05 14:59:31 +00:00
rwmutex.go sync: allow inlining the RWMutex.RUnlock fast path 2019-03-09 16:34:17 +00:00
rwmutex_test.go
waitgroup.go sync: allow inlining the Mutex.Unlock fast path 2019-03-05 14:59:31 +00:00
waitgroup_test.go sync: deflake TestWaitGroupMisuse3 2019-12-06 05:12:15 +00:00