Conversation
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.
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
changes
cached_value_sizein theEntrystruct fromusize(8 bytes on 64-bit) tou32(4 bytes). the maximum value size is capped at 512 MB (MAX_VALUE_LEN), which is well within u32's ~4 GB range.ENTRY_OVERHEADreduced from 120 to 116what was tested
cargo test -p emberkv-core)cargo test --all)entry_overhead_not_too_smalltest validates the constantcargo clippy --allcleandesign considerations
the cast from
usizetou32is always safe because values larger than 512 MB are rejected at the protocol layer. the cast fromu32tousizeis always widening on 64-bit (and 32-bit targets where usize = u32). incremental updates usesaturating_sub/saturating_addthrough usize intermediates to avoid truncation edge cases.