-
Notifications
You must be signed in to change notification settings - Fork 745
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
[Merged by Bors] - Avoid cloning snapshots during sync #3271
Conversation
71e9ab0
to
54d72d6
Compare
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.
Looks good. These assumptions seem safe to me. We will lose some snapshot cache hits due to some block delay cache misses, but it should be minor.
@@ -253,7 +253,8 @@ impl<T: EthSpec> SnapshotCache<T> { | |||
.position(|snapshot| snapshot.beacon_block_root == block_root) | |||
.map(|i| { | |||
if let Some(cache) = self.snapshots.get(i) { | |||
if block_slot > cache.beacon_block.slot() + 1 { | |||
// Avoid cloning the block during sync (when the `block_delay` is `None`). | |||
if block_slot > cache.beacon_block.slot() + 1 && block_delay.is_some() { |
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.
Very very minor point in the case where block_delay
is None
:
If we nest this if
block below into the if let Some
block would it avoid us checking block_delay
twice (assuming block_slot > cache.beacon_block.slot() + 1 == true
)?
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.
yeah good call, that's simpler
54d72d6
to
d68b1d3
Compare
bors r+ |
## Issue Addressed Closes #2944 ## Proposed Changes Remove snapshots from the cache during sync rather than cloning them. This reduces unnecessary cloning and memory fragmentation during sync. ## Additional Info This PR relies on the fact that the `block_delay` cache is not populated for blocks from sync. Relying on block delay may have the side effect that a change in `block_delay` calculation could lead to: a) more clones, if block delays are added for syncing blocks or b) less clones, if blocks near the head are erroneously provided without a `block_delay`. Case (a) would be a regression to the current status quo, and (b) is low-risk given we know that the snapshot cache is current susceptible to misses (hence `tree-states`).
Issue Addressed
Closes #2944
Proposed Changes
Remove snapshots from the cache during sync rather than cloning them. This reduces unnecessary cloning and memory fragmentation during sync.
Additional Info
This PR relies on the fact that the
block_delay
cache is not populated for blocks from sync. Relying on block delay may have the side effect that a change inblock_delay
calculation could lead to: a) more clones, if block delays are added for syncing blocks or b) less clones, if blocks near the head are erroneously provided without ablock_delay
. Case (a) would be a regression to the current status quo, and (b) is low-risk given we know that the snapshot cache is current susceptible to misses (hencetree-states
).