Skip to content
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

Implement intra_rebase to reuse identical subtrees #65

Merged
merged 2 commits into from
Mar 3, 2025

Conversation

michaelsproul
Copy link
Member

@michaelsproul michaelsproul commented Mar 3, 2025

While debugging high memory usage on Holesky, we found that the changing inactivity_scores were occupying a large amount of RAM: around 70MB of new data each epoch boundary. See:

With this change, we can reduce it down to 4MB, with a rebase op taking only 42ms.

The intra_rebase implementation is a recursive depth-first tree traversal. It's similar to rebase, but a bit simpler.

@michaelsproul michaelsproul changed the title Implement intra_rebase for self-similar lists Implement intra_rebase to reuse identical subtrees Mar 3, 2025
Copy link
Member Author

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

LGTM ;)

@michaelsproul michaelsproul merged commit e0389cb into main Mar 3, 2025
5 checks passed
@michaelsproul michaelsproul deleted the intra-rebase branch March 3, 2025 04:30
if let Some(known_subtree) = known_subtrees.get(&(current_depth, hash)) {
// Node is already known from elsewhere in the tree. We can replace it without
// looking at further subtrees.
return Ok(IntraRebaseAction::Replace(known_subtree.clone()));
Copy link
Member Author

Choose a reason for hiding this comment

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

A small further optimisation here would be to avoid doing a Replace if the known_subtree and orig are already ptr-equal, e.g. if we call intra_rebase twice in a row it should always be a Noop (we could write a test for this).

current_depth: usize,
) -> Result<IntraRebaseAction<Self>, Error> {
match &**orig {
Self::Leaf(_) | Self::PackedLeaf(_) | Self::Zero(_) => Ok(IntraRebaseAction::Noop),
Copy link
Member Author

Choose a reason for hiding this comment

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

Another optimisation would be to save some stack depth by avoiding recursing down to the leaves. Once we reached a specific depth above the leaves we could just stop recursing.

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.

1 participant