Fix swissmap size calculation by aligning with Go 1.24+ internal layout#153
Open
fsul7o wants to merge 7 commits intokpango:mainfrom
Open
Fix swissmap size calculation by aligning with Go 1.24+ internal layout#153fsul7o wants to merge 7 commits intokpango:mainfrom
fsul7o wants to merge 7 commits intokpango:mainfrom
Conversation
…map implementation Signed-off-by: fsul7o <75571344+fsul7o@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates mapSize for Go’s swissmap implementation by mirroring the Go 1.24+ internal/runtime/maps layouts so map memory-size estimation remains correct now that swissmap is the default.
Changes:
- Replaces the old bucket-era
hmapmirror with amaps.Map-aligned header and addstableHdr/groupsRefmirrors for table/group sizing. - Rewrites swissmap sizing logic to handle small-map (
dirLen == 0) vs directory-backed maps (dirLen > 0), including deduping aliased table pointers. - Adjusts slot sizing logic to account for final slot alignment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: fsul7o <75571344+fsul7o@users.noreply.github.com>
…viors Signed-off-by: fsul7o <75571344+fsul7o@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: fsul7o <75571344+fsul7o@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
mapSizefor swissmap (map_size_swiss.go) produced wildly incorrect values (e.g.2300377391887453521) after Go 1.24 made swissmap the default implementation.The root cause was that the
hmapstruct mirrored the old bucket-basedruntime.hmaplayout instead of the newinternal/runtime/maps.Map:B uint8dir unsafe.PointerdirPtr)dirLen uintptrReading
h.Bactually read byte 1 of the randomseed uintptrfield, causing(1 << h.B) * groupSizeto overflow into astronomically large values.changes
hmapto correctly mirrorinternal/runtime/maps.Map(Go 1.24+):used,seed,dirPtr,dirLen,globalDepth,globalShift,writing,tombstonePossible,clearSeq.tableHdrmirroringinternal/runtime/maps.table, andgroupsRefmirroringinternal/runtime/maps.groupsReference.mapSize:dirLen == 0→dirPtrpoints directly to one group.tableHdritself plus(lengthMask+1) × groupSizefor the groups backing array.dirLen × ptrSize).slotSizecalculation: added correct final slot alignment (alignUp(..., slotAlign)) which was missing for types likemap[uint8]int64.Operation check
Before fix
After fix