Skip to content

Commit e362741

Browse files
committed
optimizations
1 parent d00bb16 commit e362741

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

examples/sensor_test/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let readings_count = 100_000_000;
1313

1414
// 1. Initialize StageEngine
15-
let engine = StageEngine::<Reading, Reading>::with_capacity(readings_count * 64);
15+
let engine = StageEngine::<Reading, Reading>::with_capacity(readings_count);
1616

1717
// 2. Add Aggregation Stage: Reading -> Summary
1818
let mut engine = engine

src/pipe/delta.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ use crate::stage::{OutputCollector, Stage};
22
use bytemuck::Pod;
33
use std::collections::HashMap;
44
use std::marker::PhantomData;
5+
use fxhash::FxHashMap;
56

67
/// Compares the current item with the previous item associated with the same key.
78
///
89
/// This stage is useful for calculating changes or deltas between events in a stream.
910
pub struct Delta<K, T, Out, F, L> {
1011
key_fn: F,
1112
logic: L,
12-
last_values: HashMap<K, T>,
13+
last_values: FxHashMap<K, T>,
1314
_phantom: PhantomData<(T, Out)>,
1415
}
1516

@@ -25,7 +26,7 @@ where
2526
Self {
2627
key_fn,
2728
logic,
28-
last_values: HashMap::new(),
29+
last_values: FxHashMap::default(),
2930
_phantom: PhantomData,
3031
}
3132
}

src/pipe/stateful.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::stage::{OutputCollector, Stage};
22
use bytemuck::Pod;
33
use std::collections::HashMap;
44
use std::marker::PhantomData;
5+
use fxhash::FxHashMap;
56

67
/// Maintains per-key state for stateful aggregations or processing.
78
///
@@ -11,7 +12,7 @@ pub struct Stateful<K, In, Out, KF, IF, FF> {
1112
key_fn: KF,
1213
init_fn: IF,
1314
fold_fn: FF,
14-
storage: HashMap<K, Out>,
15+
storage: FxHashMap<K, Out>,
1516
_phantom: PhantomData<In>,
1617
}
1718

@@ -29,7 +30,7 @@ where
2930
key_fn,
3031
init_fn,
3132
fold_fn,
32-
storage: HashMap::new(),
33+
storage: FxHashMap::default(),
3334
_phantom: PhantomData,
3435
}
3536
}

0 commit comments

Comments
 (0)