forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 270
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
reduces std::mem::size_of::<gossip::CrdsData>() #4391
Open
behzadnouri
wants to merge
6
commits into
anza-xyz:master
Choose a base branch
from
behzadnouri:box-contact-info-cache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+274
−204
Conversation
This file contains 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
behzadnouri
force-pushed
the
box-contact-info-cache
branch
2 times, most recently
from
January 10, 2025 17:36
974fd85
to
23038ae
Compare
behzadnouri
added a commit
to behzadnouri/solana
that referenced
this pull request
Jan 10, 2025
anza-xyz#4391 adds type parameter to ContactInfo.cache but we don't want to expose that to outside of gossip crate. In order to encapsulate that change in gossip crate, this commit adds an alias for: Fn(&ContactInfo) -> R which can be used outside of gossip crate.
behzadnouri
added a commit
to behzadnouri/solana
that referenced
this pull request
Jan 10, 2025
anza-xyz#4391 adds type parameter to ContactInfo.cache but we don't want to expose that implementation detail to outside of the gossip crate. In order to encapsulate that change in gossip crate, this commit adds an alias for: Fn(&ContactInfo) -> R which can be used outside of the gossip crate.
behzadnouri
force-pushed
the
box-contact-info-cache
branch
from
January 10, 2025 19:01
23038ae
to
03c984f
Compare
anza-xyz#4391 adds type parameter to gossip ContactInfo, but CrdsData::ContactInfo(_) can only be initialized with a specific type. In order to simplify the change and avoid verbosity, this commit implements From<ContactInfo> for CrdsData which allows to generically handle different types without changing the call sites.
anza-xyz#4391 adds type parameter to ContactInfo.cache but we don't want to expose that implementation detail to outside of the gossip crate. In order to encapsulate that change in gossip crate, this commit adds an alias for: Fn(&ContactInfo) -> R which can be used outside of the gossip crate.
We no longer use LegacyContactInfo and don't need to push updates over gossip.
Because ContactInfo.cache is huge, currently std::mem::size_of::<gossip::CrdsData>() stands at 560 bytes. However only a small % of entries in gossip CRDS table are ContactInfo so this wastes a lot of memory. In order to reduce the size of CrdsData enum, the commit adds type parameter for ContactInfo.cache. For the ContactInfo stored in CRDS table we use ContactInfo.cache: Box<[SocketAddr; N]> whereas outside gossip CRDS table we avoid Box<...> overhead by just using the plain array: ContactInfo.cache: [SocketAddr; N] Doing so, * std::mem::size_of::<gossip::CrdsData>() reduces from 560 bytes to 176 bytes. * Accessing other fields of ContactInfo does not incur Box<...> overhead. * Outside gossip CRDS table, we avoid Box<...> overhead entirely.
behzadnouri
force-pushed
the
box-contact-info-cache
branch
from
January 10, 2025 19:48
03c984f
to
c3cbfe1
Compare
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.
Problem
Because
ContactInfo.cache
is huge, currentlystands at 560 bytes. However only a small % of entries in gossip CRDS table are
ContactInfo
so this wastes a lot of memory.Summary of Changes
In order to reduce the size of
CrdsData
enum, the commit adds type parameter forContactInfo.cache
. For theContactInfo
stored in CRDS table we usewhereas outside gossip CRDS table we avoid
Box<...>
overhead by just using the plain array:Doing so,
std::mem::size_of::<gossip::CrdsData>()
reduces from 560 bytes to 176 bytes.ContactInfo
does not incurBox<...>
overhead.Box<...>
overhead entirely.