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

Optimize account hash CumulativeOffset index from vec to 2-element array #33839

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions accounts-db/src/accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ const _: () = assert!(

#[derive(Default, Debug, PartialEq, Eq)]
pub struct CumulativeOffset {
pub index: Vec<usize>,
/// Since the source data in at most 2D, two indexes are enough.
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
pub index: [usize; 2],
pub start_offset: usize,
}

Expand Down Expand Up @@ -416,7 +417,7 @@ impl CumulativeOffsets {
.filter_map(|(i, len)| {
if len > 0 {
let result = CumulativeOffset {
index: vec![i],
index: [i, i],
start_offset: total_count,
};
total_count += len;
Expand Down Expand Up @@ -1373,7 +1374,7 @@ mod tests {
cumulative_offsets = Vec::with_capacity(raw.len() * v_outer.len());
}
cumulative_offsets.push(CumulativeOffset {
index: vec![i, j],
index: [i, j],
start_offset: total_count,
});
total_count += len;
Expand Down Expand Up @@ -2126,7 +2127,7 @@ mod tests {
fn test_accountsdb_cumulative_find() {
let input = CumulativeOffsets {
cumulative_offsets: vec![CumulativeOffset {
index: vec![0],
index: [0; 2],
start_offset: 0,
}],
total_count: 0,
Expand All @@ -2136,11 +2137,11 @@ mod tests {
let input = CumulativeOffsets {
cumulative_offsets: vec![
CumulativeOffset {
index: vec![0],
index: [0; 2],
start_offset: 0,
},
CumulativeOffset {
index: vec![1],
index: [1; 2],
start_offset: 2,
},
],
Expand Down