Skip to content

perf: zero-copy command parsing + keyspace fast path - #107

Merged
kacy merged 3 commits into
mainfrom
perf/zero-copy-parsing-keyspace
Feb 12, 2026
Merged

perf: zero-copy command parsing + keyspace fast path#107
kacy merged 3 commits into
mainfrom
perf/zero-copy-parsing-keyspace

Conversation

@kacy

@kacy kacy commented Feb 12, 2026

Copy link
Copy Markdown
Owner

summary

tier 2 performance optimizations from the throughput/latency audit.

  • zero-copy extract_string: validates UTF-8 in-place on the Bytes buffer with std::str::from_utf8() instead of copying to a Vec<u8> first via to_vec(). saves one allocation per string argument per command
  • get_string() on keyspace: new method returns Option<Bytes> directly, avoiding the Value enum clone wrapper. shard GET dispatch now uses this path — Bytes::clone() is just a refcount increment
  • ahash for shard routing: replaces DefaultHasher (SipHash-2-4) with ahash (~3x faster for short keys). shard routing is trusted internal logic so DoS-resistant hashing is unnecessary

what was tested

  • cargo test --workspace --features protobuf — all tests pass (994+ tests)
  • cargo clippy --workspace --features protobuf -- -D warnings — clean

design considerations

  • get_string() is additive — get() remains for callers that need the full Value. the shard dispatch wraps the result back into Value::String() to keep the ShardResponse type unchanged
  • ahash is deterministic within a process but not across restarts. this is fine for shard routing since we don't persist shard assignments

kacy added 3 commits February 12, 2026 11:56
replaces data.to_vec() + String::from_utf8() with
std::str::from_utf8() + to_owned(). validates UTF-8 directly on
the Bytes buffer without an intermediate Vec<u8> allocation,
then allocates only once for the final String.
adds Keyspace::get_string() that returns Option<Bytes> directly,
avoiding the Value enum wrapper. the shard GET dispatch now uses
this path — Bytes::clone() is just a refcount increment, and we
skip the full Value::clone() + pattern match overhead.
replaces DefaultHasher (SipHash-2-4) with ahash for shard key
routing. ahash is ~3x faster for short keys. shard routing is
trusted internal logic — the keys come from client commands, not
untrusted input that could craft hash collisions.
@kacy
kacy merged commit 2ac0105 into main Feb 12, 2026
5 of 7 checks passed
@kacy
kacy deleted the perf/zero-copy-parsing-keyspace branch February 12, 2026 17:26
kacy added a commit that referenced this pull request Feb 19, 2026
* perf: validate UTF-8 in-place in extract_string

replaces data.to_vec() + String::from_utf8() with
std::str::from_utf8() + to_owned(). validates UTF-8 directly on
the Bytes buffer without an intermediate Vec<u8> allocation,
then allocates only once for the final String.

* perf: add get_string() for direct Bytes return on GET

adds Keyspace::get_string() that returns Option<Bytes> directly,
avoiding the Value enum wrapper. the shard GET dispatch now uses
this path — Bytes::clone() is just a refcount increment, and we
skip the full Value::clone() + pattern match overhead.

* perf: use ahash for shard routing instead of SipHash

replaces DefaultHasher (SipHash-2-4) with ahash for shard key
routing. ahash is ~3x faster for short keys. shard routing is
trusted internal logic — the keys come from client commands, not
untrusted input that could craft hash collisions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant