Skip to content

perf: pack cached_value_size as u32#285

Merged
kacy merged 1 commit intomainfrom
perf/compact-entry-size
Feb 25, 2026
Merged

perf: pack cached_value_size as u32#285
kacy merged 1 commit intomainfrom
perf/compact-entry-size

Conversation

@kacy
Copy link
Copy Markdown
Owner

@kacy kacy commented Feb 25, 2026

summary

changes cached_value_size in the Entry struct from usize (8 bytes on 64-bit) to u32 (4 bytes). the maximum value size is capped at 512 MB (MAX_VALUE_LEN), which is well within u32's ~4 GB range.

what was tested

  • all 507 unit tests pass (cargo test -p emberkv-core)
  • full workspace builds and tests pass (cargo test --all)
  • entry_overhead_not_too_small test validates the constant
  • cargo clippy --all clean

design considerations

the cast from usize to u32 is always safe because values larger than 512 MB are rejected at the protocol layer. the cast from u32 to usize is always widening on 64-bit (and 32-bit targets where usize = u32). incremental updates use saturating_sub / saturating_add through usize intermediates to avoid truncation edge cases.

cached_value_size was usize (8 bytes on 64-bit) but the maximum value
size is 512 MB (MAX_VALUE_LEN), well within u32 range (~4 GB).

packing it as u32 shrinks Entry from 44 to 40 bytes. combined with
the version side table from the previous PR, Entry is now 12 bytes
smaller than the original 52-byte layout. ENTRY_OVERHEAD reduced
from 120 to 116.
@kacy kacy merged commit 9799aeb into main Feb 25, 2026
7 checks passed
@kacy kacy deleted the perf/compact-entry-size branch February 25, 2026 12:14
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