perf: eliminate double serialization in event append path #361
Labels
No labels
adr
automated
bug
chore
dependencies
documentation
enhancement
epic
github-actions
P1-high
P2-medium
P3-low
release
research
rust
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jwilger/eventcore#361
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Events are serialized twice during
execute():StreamWrites::append()(eventcore-types/src/store.rs:89) callsserde_json::to_value(&event)— produces aserde_json::Valueappend_events()then callsserde_json::to_string(event_data)to convert theValueto a JSON string for SQL bindingAt ~78 ns per serialize pass plus
to_valueoverhead, this adds ~150-200 ns per event unnecessarily. For a 100-event batch, that's ~15-20 µs of waste.Proposed Solution
Options (in order of preference):
StringinStreamWrites::append()and store the string, not theValue. Backends bind the string directly.Valueand useserde_json::to_writerto a pre-allocated buffer instead ofto_string.Option 1 is simpler and eliminates the intermediate
Valueallocation entirely.Expected Impact
~150 ns/event saved across all backends. Most impactful for high-throughput in-memory and SQLite workloads.
Location
eventcore-types/src/store.rs—StreamWrites::append()andStreamWriteEntrystructeventcore-postgres/src/lib.rs—append_events()SQL bindingeventcore-sqlite/src/lib.rs—append_events()SQL bindingBenchmark Baseline
Run
cargo bench -p eventcore-bench --bench store_operations -- 'store/append'andcargo bench -p eventcore-bench --bench serializationto measure before/after.