Skip to content

Commit bcdd8ee

Browse files
chore(perf): use static sized arrays instead of Vec<..> (#49)
Currently, the fastpfor loop is using a Vec<..> for a number of fixed size allocations. This is just kind of weird since the size of the array is known.
1 parent a616829 commit bcdd8ee

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/rust/integer_compression/codec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::rust::{FastPFOR, JustCopy, VariableByte};
22

33
pub enum Codec {
4-
FastPFor(FastPFOR),
4+
FastPFor(Box<FastPFOR>),
55
VariableByte(VariableByte),
66
JustCopy(JustCopy),
77
}
88

99
impl From<FastPFOR> for Codec {
1010
fn from(fastpfor: FastPFOR) -> Self {
11-
Codec::FastPFor(fastpfor)
11+
Codec::FastPFor(Box::new(fastpfor))
1212
}
1313
}
1414

src/rust/integer_compression/fastpfor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ pub const DEFAULT_PAGE_SIZE: NonZeroU32 = NonZeroU32::new(65536).unwrap();
3030
#[derive(Debug)]
3131
pub struct FastPFOR {
3232
/// Exception values indexed by bit width difference
33-
pub data_to_be_packed: Vec<Vec<u32>>,
33+
pub data_to_be_packed: [Vec<u32>; 33],
3434
/// Metadata buffer for encoding/decoding
3535
pub bytes_container: BytesMut,
3636
/// Maximum integers per page
3737
pub page_size: u32,
3838
/// Position trackers for exception arrays
39-
pub data_pointers: Vec<usize>,
39+
pub data_pointers: [usize; 33],
4040
/// Frequency count for each bit width:
41-
/// freqs[0..=32] = count of values needing exactly i bits
42-
pub freqs: Vec<u32>,
41+
/// `freqs[i]` = count of values needing exactly i bits
42+
pub freqs: [u32; 33],
4343
pub optimal_bits: u32,
4444
pub exception_count: u32,
4545
pub max_bits: u32,
@@ -154,9 +154,9 @@ impl FastPFOR {
154154
bytes_container: BytesMut::with_capacity(
155155
(3 * page_size / block_size + page_size) as usize,
156156
),
157-
data_to_be_packed: vec![vec![0; page_size as usize / 32 * 4]; 33],
158-
data_pointers: vec![0; 33],
159-
freqs: vec![0; 33],
157+
data_to_be_packed: std::array::from_fn(|_| vec![0; page_size as usize / 32 * 4]),
158+
data_pointers: [0; 33],
159+
freqs: [0; 33],
160160
optimal_bits: 0,
161161
exception_count: 0,
162162
max_bits: 0,

0 commit comments

Comments
 (0)