aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/map.go
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2023-01-13 16:12:47 -0500
committerDavid Chase <drchase@google.com>2023-01-23 15:51:32 +0000
commite22bd2348c8e3bfdf12197d0b0e194b66bbf5a36 (patch)
tree0c61869dae136d804b1e82091fc562cde4bf7efe /src/runtime/map.go
parente2fe35363d070bf37326d04ed28964e6ba3892da (diff)
downloadgo-e22bd2348c8e3bfdf12197d0b0e194b66bbf5a36.tar.xz
internal/abi,runtime: refactor map constants into one place
Previously TryBot-tested with bucket bits = 4. Also tested locally with bucket bits = 5. This makes it much easier to change the size of map buckets, and hopefully provides pointers to all the code that in some way depends on details of map layout. Change-Id: I9f6669d1eadd02f182d0bc3f959dc5f385fa1683 Reviewed-on: https://go-review.googlesource.com/c/go/+/462115 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/map.go')
-rw-r--r--src/runtime/map.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/runtime/map.go b/src/runtime/map.go
index f546ce8609..6179c1e371 100644
--- a/src/runtime/map.go
+++ b/src/runtime/map.go
@@ -63,20 +63,21 @@ import (
const (
// Maximum number of key/elem pairs a bucket can hold.
- bucketCntBits = 3
- bucketCnt = 1 << bucketCntBits
+ bucketCntBits = abi.MapBucketCountBits
+ bucketCnt = abi.MapBucketCount
- // Maximum average load of a bucket that triggers growth is 6.5.
+ // Maximum average load of a bucket that triggers growth is bucketCnt*13/16 (about 80% full)
+ // Because of minimum alignment rules, bucketCnt is known to be at least 8.
// Represent as loadFactorNum/loadFactorDen, to allow integer math.
- loadFactorNum = 13
loadFactorDen = 2
+ loadFactorNum = (bucketCnt * 13 / 16) * loadFactorDen
// Maximum key or elem size to keep inline (instead of mallocing per element).
// Must fit in a uint8.
// Fast versions cannot handle big elems - the cutoff size for
// fast versions in cmd/compile/internal/gc/walk.go must be at most this elem.
- maxKeySize = 128
- maxElemSize = 128
+ maxKeySize = abi.MapMaxKeyBytes
+ maxElemSize = abi.MapMaxElemBytes
// data offset should be the size of the bmap struct, but needs to be
// aligned correctly. For amd64p32 this means 64-bit alignment