aboutsummaryrefslogtreecommitdiff
path: root/src/sync/map.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2024-08-26 14:18:26 +0000
committerGopher Robot <gobot@golang.org>2024-11-18 20:35:42 +0000
commitaecb8faa91e2b40e3651ee93c8e70635ed367677 (patch)
tree2cdaf8a697386367cc4874ef74b6627af6913258 /src/sync/map.go
parent06e6b8efa4c9fbe4b8ceec8c655011117a50279a (diff)
downloadgo-aecb8faa91e2b40e3651ee93c8e70635ed367677.tar.xz
sync: make HashTrieMap[any, any] the default implementation of Map
This change adds a GOEXPERIMENT, synchashtriemap, which replaces the internals of a sync.Map with internal/sync.HashTrieMap[any, any]. The main purpose behind this change is improved performance. Across almost every benchmark, HashTrieMap[any, any] performs better than Map. Also, relax TestMapClearNoAllocations to allow for one allocation. Currently, the HashTrieMap allocates a new empty root node and stores it: that's the whole clear operation. At the cost of some complexity, we could allow Clear to have zero allocations by clearing the root node. The complexity comes down to allowing threads to race to install a new root node *or* creating a top-level mutex for installing a root node. But I'm not sure this is worth it. Whether Clear or some other operation takes the hit for allocating a single node almost certainly doesn't matter. And Clear is still much, much faster in the new implementation than the old, so I don't consider this a regression. Change-Id: I939aa70a0edf2e850cedbea239aaf29a11a77b79 Reviewed-on: https://go-review.googlesource.com/c/go/+/608335 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/sync/map.go')
-rw-r--r--src/sync/map.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/sync/map.go b/src/sync/map.go
index 4f1395110a..25181e0c78 100644
--- a/src/sync/map.go
+++ b/src/sync/map.go
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+//go:build !goexperiment.synchashtriemap
+
package sync
import (