Skip to content

Embedded strings memory reduction #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 21, 2025

Conversation

AvivDavid23
Copy link

  1. Reduce the Header size of strings
  2. Allow storing strings with length <=7 on the pointer values itself, reducing allocations

@AvivDavid23 AvivDavid23 marked this pull request as ready for review August 14, 2025 12:24
// Set the length in the first byte (after tag bits)
data_bytes[0] = (s.len() << TAG_SIZE_BITS) as u8;
data_bytes[1..1 + bytes.len()].copy_from_slice(bytes);
let data: usize = usize::from_ne_bytes(data_bytes);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent choice to use from_xx_bytes. We can accept using native endianness because strings are never written in this form.

/// Safety: Must be called on inline string(strings are valid UTF-8)
unsafe fn extract_inline_str(&self) -> &str {
let data_ptr = &self.0 as *const IValue as *const u8;
let bytes: &[u8; 8] = transmute(data_ptr);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's match it with the equivalent to_xx_bytes here to ensure endianness never plays any role in de/serialization.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a to_ne_bytes fn which I can use here

@AvivDavid23 AvivDavid23 merged commit adf71f0 into master Aug 21, 2025
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.

2 participants