-
Notifications
You must be signed in to change notification settings - Fork 59
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
Reduce alloc in copy_to_overlay #178
Merged
arkpar
merged 7 commits into
paritytech:master
from
hanabi1224:reduce_alloc_in_copy_to_overlay
Feb 6, 2023
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43331db
fix: reduce allocations in copy_to_overlay
hanabi1224 86ffde6
btree copy_to_overlay
hanabi1224 6e7ffb6
fix fmt and clippy
hanabi1224 ca9f8d7
rename
hanabi1224 59bcdde
mark TryFrom as #[cfg(test)]
hanabi1224 1af4855
revert LastKey
hanabi1224 3d40344
revert iter API change
hanabi1224 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 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 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 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 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 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 |
---|---|---|
|
@@ -357,24 +357,28 @@ pub mod commit_overlay { | |
use super::*; | ||
use crate::{ | ||
column::{ColId, Column}, | ||
db::{BTreeCommitOverlay, Operation}, | ||
db::{BTreeCommitOverlay, Operation, ValuePtr}, | ||
error::Result, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct BTreeChangeSet { | ||
pub col: ColId, | ||
pub changes: Vec<Operation<Vec<u8>, Vec<u8>>>, | ||
pub changes: Vec<Operation<ValuePtr, ValuePtr>>, | ||
} | ||
|
||
impl BTreeChangeSet { | ||
pub fn new(col: ColId) -> Self { | ||
BTreeChangeSet { col, changes: Default::default() } | ||
} | ||
|
||
pub fn push(&mut self, change: Operation<Vec<u8>, Vec<u8>>) { | ||
pub fn push(&mut self, change: Operation<Value, Value>) { | ||
// No key hashing | ||
self.changes.push(change); | ||
self.changes.push(match change { | ||
Operation::Set(k, v) => Operation::Set(k.into(), v.into()), | ||
Operation::Dereference(k) => Operation::Dereference(k.into()), | ||
Operation::Reference(k) => Operation::Reference(k.into()), | ||
}); | ||
} | ||
|
||
pub fn copy_to_overlay( | ||
|
@@ -388,16 +392,16 @@ pub mod commit_overlay { | |
for change in self.changes.iter() { | ||
match change { | ||
Operation::Set(key, value) => { | ||
*bytes += key.len(); | ||
*bytes += value.len(); | ||
*bytes += key.value().len(); | ||
*bytes += value.value().len(); | ||
overlay.insert(key.clone(), (record_id, Some(value.clone()))); | ||
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.
|
||
}, | ||
Operation::Dereference(key) => { | ||
// Don't add removed ref-counted values to overlay. | ||
// (current ref_counted implementation does not | ||
// make much sense for btree indexed content). | ||
if !ref_counted { | ||
*bytes += key.len(); | ||
*bytes += key.value().len(); | ||
overlay.insert(key.clone(), (record_id, None)); | ||
} | ||
}, | ||
|
This file contains 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
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.
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.
I am a bit hesitant to switch this one to rc as it changes the iterator api. Seeked is not really useful, At will be to save one key memory per iterator and a mem copy of the key on all alloc (could use an allocated buffer but not sure if relevant) but the iterator is nowhere near performant or trying to be.
Personally I would rather keep the rc to the change overlay only.
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.
Could you elaborate on which API to keep unchanged? I just tried reverting it here but it does not change any API signature. commit: 1af4855
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.
Just iterator
next
andprev
returns IterResult that used to contain plain Vec (as used in the fuzzer, I mean the change to the fuzzer could also be reverted then).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.
@cheme Done. Please take another look. (Some changes come from
cargo clippy --fix
and I didn't revert them)