Skip to content

perf: build + serialization fast paths - #106

Merged
kacy merged 5 commits into
mainfrom
perf/build-serialization-fast-paths
Feb 12, 2026
Merged

perf: build + serialization fast paths#106
kacy merged 5 commits into
mainfrom
perf/build-serialization-fast-paths

Conversation

@kacy

@kacy kacy commented Feb 12, 2026

Copy link
Copy Markdown
Owner

summary

tier 1 performance optimizations from the throughput/latency audit. these are the highest-impact, lowest-risk changes.

  • release profile: thin LTO, single codegen unit, symbol stripping — estimated 8-15% throughput improvement from better cross-crate inlining and register allocation
  • pre-computed wire bytes: common RESP3 responses (OK, PONG, NULL, 0, 1, -1) are serialized from constants instead of formatting each field. bypasses the general serialize path for the hottest responses
  • AOF buffer capacity hints: AofRecord::estimated_size() pre-computes the serialized size so to_bytes() allocates once instead of growing 2-4 times per record
  • snapshot buffer capacity hints: same pattern for SnapEntry::write_entry() — single allocation for the entry buffer

intentionally skipped panic = "abort" to preserve stack unwinding for graceful shutdown.

what was tested

  • cargo test --workspace --features protobuf — all tests pass
  • cargo clippy --workspace --features protobuf -- -D warnings — clean
  • existing round-trip tests cover serialization correctness for all AOF record types and snapshot entry types

kacy added 5 commits February 12, 2026 11:50
thin LTO gives cross-crate inlining with ~30% less compile time
than fat LTO. codegen-units = 1 enables maximum LLVM optimization
within each crate. strip = "symbols" reduces binary size ~40% with
no runtime cost.

intentionally skip panic = "abort" to preserve stack unwinding
for graceful shutdown.
adds a `wire` module with pre-serialized byte constants for OK, PONG,
NULL, and small integers (0, 1, -1). Frame::serialize() now matches
these common values and writes the constant bytes directly, avoiding
per-field formatting overhead.

these are the hottest responses in typical workloads — SET returns OK,
EXISTS/DEL/EXPIRE return 0 or 1, GET misses return NULL.
AofRecord::to_bytes() now pre-computes the expected size via
estimated_size() and allocates with Vec::with_capacity(). this
eliminates 2-4 intermediate reallocations per persistence write,
especially for SET records with large values.
SnapEntry::estimated_size() pre-computes the serialized size so
write_entry() can allocate the buffer in a single shot. eliminates
repeated growth + copy cycles for entries with large values or
many collection elements.
@kacy
kacy merged commit 9c62862 into main Feb 12, 2026
7 checks passed
@kacy
kacy deleted the perf/build-serialization-fast-paths branch February 12, 2026 17:26
kacy added a commit that referenced this pull request Feb 19, 2026
* perf: enable thin LTO, single codegen unit, and symbol stripping

thin LTO gives cross-crate inlining with ~30% less compile time
than fat LTO. codegen-units = 1 enables maximum LLVM optimization
within each crate. strip = "symbols" reduces binary size ~40% with
no runtime cost.

intentionally skip panic = "abort" to preserve stack unwinding
for graceful shutdown.

* perf: pre-computed wire bytes for common RESP3 responses

adds a `wire` module with pre-serialized byte constants for OK, PONG,
NULL, and small integers (0, 1, -1). Frame::serialize() now matches
these common values and writes the constant bytes directly, avoiding
per-field formatting overhead.

these are the hottest responses in typical workloads — SET returns OK,
EXISTS/DEL/EXPIRE return 0 or 1, GET misses return NULL.

* perf: add capacity hints to AOF record serialization buffer

AofRecord::to_bytes() now pre-computes the expected size via
estimated_size() and allocates with Vec::with_capacity(). this
eliminates 2-4 intermediate reallocations per persistence write,
especially for SET records with large values.

* perf: add capacity hints to snapshot entry serialization buffer

SnapEntry::estimated_size() pre-computes the serialized size so
write_entry() can allocate the buffer in a single shot. eliminates
repeated growth + copy cycles for entries with large values or
many collection elements.

* style: fix formatting in persistence capacity hints
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