Skip to content

Conversation

michaelsproul
Copy link
Member

@michaelsproul michaelsproul commented Oct 22, 2024

Implement a much-thought-about feature to track the differential size of multiple data structures stored using structural sharing!


pub trait MemorySize {
/// The memory address of this item.
fn self_pointer(&self) -> usize;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We found a bug on the MemorySize impl for BeaconState where we were returning the &BeaconState from self_pointer. This meant that mutating a beacon state without cloning it would cause the memory tracker to skip over the state when provided a second time, because it thought the pointer had already been seen.

We should probably make sure that pointers returned by self_pointer are immutable, i.e. the address uniquely determines the contents at that address.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried using Arc, but ran into issues with test because of wrapping impl List in Arc. Will look into it as I keep working on Lighthouse#7449

@michaelsproul michaelsproul merged commit 6f67c04 into main Jul 28, 2025
5 checks passed
@michaelsproul michaelsproul deleted the mem-usage branch July 28, 2025 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants