-
Notifications
You must be signed in to change notification settings - Fork 117
perf(l1): avoid unnecesary work on bloom and keep a per layer bloom #5176
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
Open
edg-l
wants to merge
7
commits into
main
Choose a base branch
from
filter_bloom_per_layer
base: main
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.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5547416
Avoid unnecesary work on bloom and keep a per layer bloom
edg-l 394badd
fix
edg-l 7479bb2
changelog
edg-l 16e1f11
typo
edg-l b5f6fd0
lint
edg-l 3fd9ba4
Merge branch 'main' into filter_bloom_per_layer
edg-l 999005a
remove vec
edg-l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,10 @@ struct TrieLayer { | |
| nodes: Arc<FxHashMap<Vec<u8>, Vec<u8>>>, | ||
| parent: H256, | ||
| id: usize, | ||
| /// Per layer bloom filter, None if the size was exceeded (exceedingly rare). | ||
| /// Having a bloom per layer avoids the cost of rehashing each key every time we rebuild the globam bloom, | ||
| /// since merge simply uses the u64 hashed keys instead of rehashing. | ||
| bloom: Option<qfilter::Filter>, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't change it right now, but I think we should start referring to this as "query filter", as we're not necessarily relying on the Bloom implementation (approximate query filter is the "generic" name, but too long). |
||
| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
|
|
@@ -110,17 +114,30 @@ impl TrieLayerCache { | |
| return; | ||
| } | ||
|
|
||
| // add this new bloom to the global one. | ||
| if let Some(filter) = &mut self.bloom { | ||
| let mut bloom = Self::create_filter().ok(); | ||
|
|
||
| // create the layer bloom, this is the only place where hashing of keys happens. | ||
| if let Some(filter) = &mut bloom { | ||
| for (p, _) in &key_values { | ||
| if let Err(qfilter::Error::CapacityExceeded) = filter.insert(p.as_ref()) { | ||
| tracing::warn!("TrieLayerCache: put_batch capacity exceeded"); | ||
| self.bloom = None; | ||
| tracing::warn!("TrieLayerCache: put_batch per layer capacity exceeded"); | ||
| bloom = None; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // add this new bloom to the global one via merge | ||
| if let Some(filter) = &mut self.bloom | ||
| && let Some(new_filter) = &bloom | ||
| { | ||
| if let Err(qfilter::Error::CapacityExceeded) = filter.merge(false, new_filter) { | ||
| tracing::warn!("TrieLayerCache: put_batch merge capacity exceeded"); | ||
| self.bloom = None; | ||
| bloom = None; | ||
| } | ||
| } | ||
|
|
||
| let nodes: FxHashMap<Vec<u8>, Vec<u8>> = key_values | ||
| .into_iter() | ||
| .map(|(path, value)| (path.into_vec(), value)) | ||
|
|
@@ -131,6 +148,7 @@ impl TrieLayerCache { | |
| nodes: Arc::new(nodes), | ||
| parent, | ||
| id: self.last_id, | ||
| bloom, | ||
| }; | ||
| self.layers.insert(state_root, Arc::new(entry)); | ||
| } | ||
|
|
@@ -141,22 +159,10 @@ impl TrieLayerCache { | |
| .layers | ||
| .values() | ||
| .par_bridge() | ||
| .map(|entry| { | ||
| let Ok(mut bloom) = Self::create_filter() else { | ||
| tracing::warn!("TrieLayerCache: rebuild_bloom could not create filter"); | ||
| return None; | ||
| }; | ||
| for (p, _) in entry.nodes.iter() { | ||
| if let Err(qfilter::Error::CapacityExceeded) = bloom.insert(p) { | ||
| tracing::warn!("TrieLayerCache: rebuild_bloom capacity exceeded"); | ||
| return None; | ||
| } | ||
| } | ||
| Some(bloom) | ||
| }) | ||
| .map(|entry| entry.bloom.as_ref()) | ||
| .collect(); | ||
|
|
||
| let Some(mut ret) = blooms.pop().flatten() else { | ||
| let Some(mut ret) = blooms.pop().flatten().cloned() else { | ||
edg-l marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| tracing::warn!("TrieLayerCache: rebuild_bloom no valid bloom found"); | ||
| self.bloom = None; | ||
| return; | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.