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

perf: in_memory #12585

Open
malik672 opened this issue Nov 15, 2024 · 1 comment
Open

perf: in_memory #12585

malik672 opened this issue Nov 15, 2024 · 1 comment
Labels
C-enhancement New feature or request S-needs-triage This issue needs to be labelled

Comments

@malik672
Copy link
Contributor

Describe the feature

might be wrong but in_memory file is it not better to remove block below persisted height than to clear then re-insert in the for loop

        numbers.retain(|&block_num, _| block_num > persisted_height);

            // drain all blocks and only keep the ones that are not persisted (below the persisted
            // height)
            let mut old_blocks = blocks
                .drain()
                .filter(|(_, b)| b.block_ref().block().number > persisted_height)
                .map(|(_, b)| b.block.clone())
                .collect::<Vec<_>>();

            // sort the blocks by number so we can insert them back in natural order (low -> high)
            old_blocks.sort_unstable_by_key(|block| block.block().number);

            // re-insert the blocks in natural order and connect them to their parent blocks
            for block in old_blocks {
                let parent = blocks.get(&block.block().parent_hash).cloned();
                let block_state = BlockState::with_parent(block, parent);
                let hash = block_state.hash();
                // append new blocks
                blocks.insert(hash, Arc::new(block_state));
            }

Additional context

No response

@malik672 malik672 added C-enhancement New feature or request S-needs-triage This issue needs to be labelled labels Nov 15, 2024
@mattsse
Copy link
Collaborator

mattsse commented Nov 16, 2024

we need to re-insert because of this

let parent = blocks.get(&block.block().parent_hash).cloned();
let block_state = BlockState::with_parent(block, parent);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request S-needs-triage This issue needs to be labelled
Projects
Status: Todo
Development

No branches or pull requests

2 participants