From e22bd2348c8e3bfdf12197d0b0e194b66bbf5a36 Mon Sep 17 00:00:00 2001 From: David Chase Date: Fri, 13 Jan 2023 16:12:47 -0500 Subject: 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 Run-TryBot: David Chase Reviewed-by: Austin Clements --- src/runtime/map.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/runtime/map.go') 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 -- cgit v1.3-5-g45d5