-
Notifications
You must be signed in to change notification settings - Fork 14
Use a slice to store section address for a field #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable-v17
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request optimizes memory usage and lookup performance for the fieldsSectionsMap data structure by replacing an inner map with a slice. The change leverages the fact that section IDs form a dense range from 0 to SectionCount.
Key Changes:
- Changed
fieldsSectionsMaptype from[]map[uint16]uint64to[][]uint64, eliminating map overhead - Added
SectionCountconstant to track the total number of section types - Refactored
loadFieldmethod to return the field section map instead of accepting it as a parameter
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| section.go | Adds SectionCount constant to automatically track the total number of section types for sizing slice allocations |
| segment.go | Updates fieldsSectionsMap type definition, refactors loadField signature to return the section map, and initializes section maps as slices instead of maps |
| write.go | Removes obsolete FIXME comment about hard-coding section count, as the code now properly uses dynamic len(segmentSections) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Add new sections above this line. | ||
| // SectionCount automatically reflects the total number of sections | ||
| // and is used to track how many sections can be registered. | ||
| SectionCount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, rename to NumSections - as this is not quite a section enum.
| // create an address mapping array for each of the segment sections | ||
| // if the field has a valid section index, then the address will be non-zero | ||
| // else it will be zero. | ||
| fieldSectionMap := make([]uint64, SectionCount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite* follow the reason for this in this method - what're we using this for.
fieldsSectionsMapis of type[]map[uint16]uint64, mappingfieldID → section → address.SectionCount, determined at process initialization, we can replace the inner map with a slice of lengthSectionCount.