diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2020-04-08 03:08:21 +0700 |
---|---|---|
committer | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2020-04-09 03:18:43 +0000 |
commit | 98b6c6aca6fd4185f97dc40137707f4d8df8aa7c (patch) | |
tree | 77ede3c1c256cf72943fcd824cd3f1a0aad23b55 /src/runtime/map_benchmark_test.go | |
parent | 346d7d273c864411022f809945627866f6bc4cc6 (diff) | |
download | go-98b6c6aca6fd4185f97dc40137707f4d8df8aa7c.tar.gz go-98b6c6aca6fd4185f97dc40137707f4d8df8aa7c.zip |
cmd/compile: do not allocate bucket for non-escaping map
For map with hint larger than BUCKETSIZE, makemap ignore allocated
bucket and allocate buckets itself. So do not allocate bucket in
this case, save us the cost of zeroing+assignment to the bucket.
name old time/op new time/op delta
NewEmptyMap-12 3.89ns ± 4% 3.88ns ± 2% ~ (p=0.939 n=19+20)
NewSmallMap-12 23.3ns ± 3% 23.1ns ± 2% ~ (p=0.307 n=18+17)
NewEmptyMapHintLessThan8-12 6.43ns ± 3% 6.31ns ± 2% -1.72% (p=0.000 n=19+18)
NewEmptyMapHintGreaterThan8-12 159ns ± 2% 150ns ± 1% -5.79% (p=0.000 n=20+18)
Benchmark run with commit ab7c174 reverted, see #38314.
Fixes #20184
Change-Id: Ic021f57454c3a0dd50601d73bbd77b8faf8d93b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/227458
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/map_benchmark_test.go')
-rw-r--r-- | src/runtime/map_benchmark_test.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/runtime/map_benchmark_test.go b/src/runtime/map_benchmark_test.go index bae1aa0dbd..893cb6c5b6 100644 --- a/src/runtime/map_benchmark_test.go +++ b/src/runtime/map_benchmark_test.go @@ -513,3 +513,22 @@ func BenchmarkMapInterfacePtr(b *testing.B) { BoolSink = m[key] } } + +var ( + hintLessThan8 = 7 + hintGreaterThan8 = 32 +) + +func BenchmarkNewEmptyMapHintLessThan8(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + _ = make(map[int]int, hintLessThan8) + } +} + +func BenchmarkNewEmptyMapHintGreaterThan8(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + _ = make(map[int]int, hintGreaterThan8) + } +} |