diff options
| author | Michael Pratt <mpratt@google.com> | 2024-08-14 11:21:28 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-10-28 20:35:25 +0000 |
| commit | 77e3d8cf13a31343ba98268c2dddf6bc41f6ce4c (patch) | |
| tree | c1f21ea1356d5cccf04ae86aa4ad6539160106cb /src/cmd/compile/internal/reflectdata | |
| parent | bb46b754bebb0e820d74fd9eb02635afbdf5a3bd (diff) | |
| download | go-77e3d8cf13a31343ba98268c2dddf6bc41f6ce4c.tar.xz | |
internal/runtime/maps: small maps point directly to a group
If the map contains 8 or fewer entries, it is wasteful to have a
directory that points to a table that points to a group.
Add a special case that replaces the directory with a direct pointer to
a group.
We could theoretically do similar for single table maps (no directory,
just point directly to a table), but that is left for later.
For #54766.
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-swissmap
Change-Id: I6fc04dfc11c31dadfe5b5d6481b4c4abd43d48ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/611188
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/cmd/compile/internal/reflectdata')
| -rw-r--r-- | src/cmd/compile/internal/reflectdata/map_swiss.go | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/reflectdata/map_swiss.go b/src/cmd/compile/internal/reflectdata/map_swiss.go index 2037d0473f..a76864bdff 100644 --- a/src/cmd/compile/internal/reflectdata/map_swiss.go +++ b/src/cmd/compile/internal/reflectdata/map_swiss.go @@ -144,7 +144,8 @@ func SwissMapType() *types.Type { // typ unsafe.Pointer // *abi.SwissMapType // seed uintptr // - // directory []*table + // dirPtr unsafe.Pointer + // dirLen int // // globalDepth uint8 // // N.B Padding @@ -156,7 +157,8 @@ func SwissMapType() *types.Type { makefield("used", types.Types[types.TUINT64]), makefield("typ", types.Types[types.TUNSAFEPTR]), makefield("seed", types.Types[types.TUINTPTR]), - makefield("directory", types.NewSlice(types.NewPtr(swissTableType()))), + makefield("dirPtr", types.Types[types.TUNSAFEPTR]), + makefield("dirLen", types.Types[types.TINT]), makefield("globalDepth", types.Types[types.TUINT8]), makefield("clearSeq", types.Types[types.TUINT64]), } @@ -169,9 +171,9 @@ func SwissMapType() *types.Type { m.SetUnderlying(types.NewStruct(fields)) types.CalcSize(m) - // The size of Map should be 64 bytes on 64 bit - // and 40 bytes on 32 bit platforms. - if size := int64(2*8 + 6*types.PtrSize); m.Size() != size { + // The size of Map should be 56 bytes on 64 bit + // and 36 bytes on 32 bit platforms. + if size := int64(2*8 + 5*types.PtrSize /* one extra for globalDepth + padding */); m.Size() != size { base.Fatalf("internal/runtime/maps.Map size not correct: got %d, want %d", m.Size(), size) } @@ -204,7 +206,9 @@ func SwissMapIterType() *types.Type { // // dirIdx int // - // tab *table + // tab *table + // groupSmall_typ unsafe.Pointer // *SwissMapType + // groupSmall_data unsafe.Pointer // // entryIdx uint64 // } @@ -220,10 +224,12 @@ func SwissMapIterType() *types.Type { makefield("globalDepth", types.Types[types.TUINT8]), makefield("dirIdx", types.Types[types.TINT]), makefield("tab", types.NewPtr(swissTableType())), + makefield("groupSmall_typ", types.Types[types.TUNSAFEPTR]), + makefield("groupSmall_data", types.Types[types.TUNSAFEPTR]), makefield("entryIdx", types.Types[types.TUINT64]), } - // build iterator struct hswissing the above fields + // build iterator struct holding the above fields n := ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, ir.Pkgs.InternalMaps.Lookup("Iter")) iter := types.NewNamed(n) n.SetType(iter) @@ -232,9 +238,9 @@ func SwissMapIterType() *types.Type { iter.SetUnderlying(types.NewStruct(fields)) types.CalcSize(iter) - // The size of Iter should be 88 bytes on 64 bit - // and 60 bytes on 32 bit platforms. - if size := 7*types.PtrSize /* one extra for globalDepth + padding */ + 4*8; iter.Size() != int64(size) { + // The size of Iter should be 104 bytes on 64 bit + // and 68 bytes on 32 bit platforms. + if size := 9*types.PtrSize /* one extra for globalDepth + padding */ + 4*8; iter.Size() != int64(size) { base.Fatalf("internal/runtime/maps.Iter size not correct: got %d, want %d", iter.Size(), size) } |
