Skip to content

Conversation

@CascadingRadium
Copy link
Member

@CascadingRadium CascadingRadium commented Dec 24, 2025

  • Currently, fieldsSectionsMap is of type []map[uint16]uint64, mapping fieldID → section → address.
  • Since the section domain is a dense range from 0 to SectionCount, determined at process initialization, we can replace the inner map with a slice of length SectionCount.
  • This avoids map overhead and reduces both memory usage and lookup cost.

@CascadingRadium CascadingRadium changed the title Use slice to map section address for a field Use a slice to store section address for a field Dec 24, 2025
Copy link
Contributor

Copilot AI left a 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 fieldsSectionsMap type from []map[uint16]uint64 to [][]uint64, eliminating map overhead
  • Added SectionCount constant to track the total number of section types
  • Refactored loadField method 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
Copy link
Member

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)
Copy link
Member

@abhinavdangeti abhinavdangeti Dec 30, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants