perf: reduce per-event allocations in sqlitestore and pgstore Load paths #144
Labels
No labels
bug
documentation
enhancement
investigation
nice-to-have
performance
production-ready
testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ash/eskit#144
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
Benchmark shows 45 allocations per event on Load for sqlitestore:
For the #1 Go event sourcing framework, this is unacceptable. Target: <10 allocs/event.
Root Causes
string(buf.idBuf)for ID — converts byte slice to string (1 alloc)time.Parse(RFC3339Nano, ts)— parses timestamp string (1 alloc)DeserializeWithUpcastingCodec— unmarshal + type assertion (2+ allocs)json.Unmarshalfor metadata.Extra — when non-empty (1 alloc)eskit.Event[E]to sliceProposed Fixes
Quick wins (no schema change)
sql.RawBytesfor TEXT columns instead ofstring— avoids driver allocation, reuses row buffer. Copy only what we need.unsafe.Stringfor zero-copy string creation where safe (same goroutine, before Next() call)time.Parse— usetime.Unixif we can store as integer. If not, at least cache the time.Location.Medium effort (schema migration)
Architecture
go test -cpuprofileandgo test -memprofileto find exact hot spotsRequirements
ash referenced this issue2026-03-01 12:10:14 +00:00