Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

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