perf: use CompactString for keys (SSO ≤24 bytes)#228
Merged
Conversation
add auth, election, and raft_transport to the modules table and features list. fix emberkv-core typo → ember-core in the related crates table.
hot-path quick wins from performance audit (phase A): - fuse double hash probe on GET/GET_STRING into single lookup that checks expiry inline, eliminating ~2M redundant probes/sec - cache value_size in Entry struct so memory accounting is O(1) instead of walking entire collections on every mutation - shrink last_access from u64 ms to u32 secs, saving 4 bytes/entry and improving cache-line packing for the hot Entry struct - replace allocating peek_command_name (3 heap allocs per MULTI/EXEC command) with zero-allocation eq_ignore_ascii_case comparisons
replace Box<str> with compact_str::CompactString for all keyspace keys. CompactString inlines strings up to 24 bytes on the stack, eliminating heap allocation for the vast majority of real cache keys (e.g. "user:123", "session:abc", "rate:ip:1.2.3.4"). - Box<str>: 16 bytes on stack (ptr + len), always heap-allocates - CompactString: 24 bytes on stack, inlines ≤24 byte strings the extra 8 bytes per key struct is offset by eliminating heap allocation overhead (typically 16-32 bytes per allocation) for short keys. lookups work unchanged since CompactString implements Borrow<str>. ENTRY_OVERHEAD bumped from 120 to 128 to account for the larger key struct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
Box<str>withcompact_str::CompactStringfor all keyspace keys across keyspace, dropper, concurrent keyspace, and memory trackingENTRY_OVERHEADbumped from 120 → 128 to reflect the larger key struct (24 vs 16 bytes)what was tested
cargo test -p emberkv-core --lib— 345 tests passcargo check -p emberkv-core— clean buildcargo clippy -p emberkv-core --no-deps— no new warnings (8 pre-existing doc_lazy_continuation in sorted_set.rs)design considerations
the 8-byte increase per key struct is more than offset by eliminating heap allocator overhead (16-32 bytes per allocation) for keys under 24 bytes. lookups work unchanged since
CompactStringimplementsBorrow<str>,Hash, andEq. thecompact_strcrate is well-maintained and widely used (~36M downloads).