diff options
| author | Michael Pratt <mpratt@google.com> | 2024-10-25 15:08:54 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-10-30 15:43:54 +0000 |
| commit | 63ba2b9d84dede1df107db30b4ff8139711402eb (patch) | |
| tree | ab604c55740391f9205499bd0745685191a91020 /src/runtime | |
| parent | aefb173b0a1c1edfdd631b8b4ac752b947ab80a8 (diff) | |
| download | go-63ba2b9d84dede1df107db30b4ff8139711402eb.tar.xz | |
cmd/compile,internal/runtime/maps: stack allocated maps and small alloc
The compiler will stack allocate the Map struct and initial group if
possible.
Stack maps are initialized inline without calling into the runtime.
Small heap allocated maps use makemap_small.
These are the same heuristics as existing maps.
For #54766.
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-swissmap
Change-Id: I6c371d1309716fd1c38a3212d417b3c76db5c9b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/622042
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/map_swiss.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/runtime/map_swiss.go b/src/runtime/map_swiss.go index 3a6f40252a..75c72b20f5 100644 --- a/src/runtime/map_swiss.go +++ b/src/runtime/map_swiss.go @@ -37,24 +37,23 @@ func makemap64(t *abi.SwissMapType, hint int64, m *maps.Map) *maps.Map { } // makemap_small implements Go map creation for make(map[k]v) and -// make(map[k]v, hint) when hint is known to be at most bucketCnt +// make(map[k]v, hint) when hint is known to be at most abi.SwissMapGroupSlots // at compile time and the map needs to be allocated on the heap. func makemap_small() *maps.Map { - panic("unimplemented") + return maps.NewEmptyMap() } // makemap implements Go map creation for make(map[k]v, hint). -// If the compiler has determined that the map or the first bucket -// can be created on the stack, h and/or bucket may be non-nil. -// If h != nil, the map can be created directly in h. -// If h.buckets != nil, bucket pointed to can be used as the first bucket. +// If the compiler has determined that the map or the first group +// can be created on the stack, m and optionally m.dirPtr may be non-nil. +// If m != nil, the map can be created directly in m. +// If m.dirPtr != nil, it points to a group usable for a small map. func makemap(t *abi.SwissMapType, hint int, m *maps.Map) *maps.Map { if hint < 0 { hint = 0 } - // TODO: use existing m - return maps.NewMap(t, uintptr(hint), maxAlloc) + return maps.NewMap(t, uintptr(hint), m, maxAlloc) } // mapaccess1 returns a pointer to h[key]. Never returns nil, instead |
