Problem
InMemoryEventStore::read_stream() clones every event during reads (event.clone() at eventcore-memory/src/lib.rs:110). For 1000 events, that's 1000 heap allocations just to read state.
Benchmark: read 1000 events takes 43 µs (22M elem/sec). The cloning overhead is a portion of this.
Proposed Solution
Store events as Arc<dyn Any + Send + Sync> instead of Box<dyn Any + Send + Sync>. Reads would clone the Arc (cheap pointer increment) rather than deep-cloning the event data.
Expected Impact
Minor — estimated 43 µs → ~20 µs for reading 1000 events. The in-memory store is primarily used for testing, so this is low priority.
Caveats
The in-memory store is designed for testing and development, not production workloads. This optimization matters only if the in-memory store is used for benchmarking other components where read overhead should be minimized.
Location
eventcore-memory/src/lib.rs — storage types and read_stream() method.
Benchmark Baseline
Run cargo bench -p eventcore-bench --bench store_operations -- 'store/read_stream/memory' to measure before/after.
Problem
InMemoryEventStore::read_stream()clones every event during reads (event.clone()ateventcore-memory/src/lib.rs:110). For 1000 events, that's 1000 heap allocations just to read state.Benchmark: read 1000 events takes 43 µs (22M elem/sec). The cloning overhead is a portion of this.
Proposed Solution
Store events as
Arc<dyn Any + Send + Sync>instead ofBox<dyn Any + Send + Sync>. Reads would clone theArc(cheap pointer increment) rather than deep-cloning the event data.Expected Impact
Minor — estimated 43 µs → ~20 µs for reading 1000 events. The in-memory store is primarily used for testing, so this is low priority.
Caveats
The in-memory store is designed for testing and development, not production workloads. This optimization matters only if the in-memory store is used for benchmarking other components where read overhead should be minimized.
Location
eventcore-memory/src/lib.rs— storage types andread_stream()method.Benchmark Baseline
Run
cargo bench -p eventcore-bench --bench store_operations -- 'store/read_stream/memory'to measure before/after.