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

feat(trie): use Arc instead of references for nodes and state cursor factories #13868

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fgimenez
Copy link
Member

Extracted from #13749

The reference parameters in InMemoryTrieCursorFactory and HashedPostStateCursorFactory cause lifetime problems when they are used to create and spawn StateRootTask, this PR changes those parameters to Arcs.

Copy link

codspeed-hq bot commented Jan 19, 2025

CodSpeed Performance Report

Merging #13868 will not alter performance

Comparing fgimenez/trie-arc-nodes (63b94ab) with main (6cc660c)

Summary

✅ 77 untouched benchmarks

@fgimenez fgimenez added A-trie Related to Merkle Patricia Trie implementation C-perf A change motivated by improving speed, memory usage or disk footprint labels Jan 20, 2025
Copy link
Collaborator

@shekhirin shekhirin left a comment

Choose a reason for hiding this comment

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

I see a bunch of clones of non-Arc values, I think it can get pretty expensive given that these cursor codepaths are hit often. To avoid that, we will need to further propagate the usage of Arcs, right?


fn hashed_account_cursor(&self) -> Result<Self::AccountCursor, DatabaseError> {
let cursor = self.cursor_factory.hashed_account_cursor()?;
Ok(HashedPostStateAccountCursor::new(cursor, &self.post_state.accounts))
Ok(HashedPostStateAccountCursor::new(cursor, self.post_state.accounts.clone()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

also here, for example

@fgimenez
Copy link
Member Author

I see a bunch of clones of non-Arc values, I think it can get pretty expensive given that these cursor codepaths are hit often. To avoid that, we will need to further propagate the usage of Arcs, right?

yep, looking into it rn

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

given that all of these work with refs but we need an owned instance for the root task, I wonder if we can introduce owned factories which trait impls are then just delegate to .ref()?

@mattsse mattsse added this to the Release 1.2.0 milestone Jan 20, 2025
@fgimenez
Copy link
Member Author

given that all of these work with refs but we need an owned instance for the root task, I wonder if we can introduce owned factories which trait impls are then just delegate to .ref()?

sounds great, will give it a try 🙌

@fgimenez fgimenez force-pushed the fgimenez/trie-arc-nodes branch from f33988f to 63b94ab Compare January 20, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trie Related to Merkle Patricia Trie implementation C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants