-
Notifications
You must be signed in to change notification settings - Fork 0
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
Embedded strings memory reduction #7
Conversation
AvivDavid23
commented
Aug 13, 2025
- Reduce the Header size of strings
- Allow storing strings with length <=7 on the pointer values itself, reducing allocations
// 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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