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

Optimizes AppendVec::get_account_sizes() when using file io #2083

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions accounts-db/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ impl AppendVec {

/// for each offset in `sorted_offsets`, get the size of the account. No other information is needed for the account.
pub(crate) fn get_account_sizes(&self, sorted_offsets: &[usize]) -> Vec<usize> {
let mut result = Vec::with_capacity(sorted_offsets.len());
let mut account_sizes = Vec::with_capacity(sorted_offsets.len());
match &self.backing {
AppendVecFileBacking::Mmap(Mmap { mmap, .. }) => {
let slice = self.get_valid_slice_from_mmap(mmap);
Expand All @@ -996,18 +996,29 @@ impl AppendVec {
// data doesn't fit, so don't include
break;
}
result.push(next.stored_size_aligned);
account_sizes.push(next.stored_size_aligned);
}
}
AppendVecFileBacking::File(_file) => {
for &offset in sorted_offsets {
self.get_stored_account_meta_callback(offset, |stored_meta| {
result.push(stored_meta.stored_size());
});
AppendVecFileBacking::File(file) => {
// self.len() is an atomic load, so only do it once
let valid_file_len = self.len();
let mut buffer = [0u8; mem::size_of::<StoredMeta>()];
for offset in sorted_offsets {
let Some(bytes_read) =
read_into_buffer(file, valid_file_len, *offset, &mut buffer).ok()
else {
break;
};
let bytes = ValidSlice(&buffer[..bytes_read]);
let Some((stored_meta, _next)) = Self::get_type::<StoredMeta>(bytes, 0) else {
break;
};
let stored_size = aligned_stored_size(stored_meta.data_len as usize);
account_sizes.push(stored_size);
HaoranYi marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
result
account_sizes
}

/// iterate over all pubkeys and call `callback`.
Expand Down