Skip to content
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

prealloc size of Lower::lower_into_rust_buffer #2420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dev-ardi
Copy link

No description provided.

@dev-ardi dev-ardi requested a review from a team as a code owner January 28, 2025 16:45
@dev-ardi dev-ardi requested review from bendk and removed request for a team January 28, 2025 16:45
Copy link
Contributor

@bendk bendk left a comment

Choose a reason for hiding this comment

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

Seems like a good idea, but I'd love some more data before we try to make this optimization.

@@ -245,7 +245,7 @@ pub unsafe trait Lower<UT>: Sized {

/// Convenience method
fn lower_into_rust_buffer(obj: Self) -> RustBuffer {
let mut buf = ::std::vec::Vec::new();
let mut buf = ::std::vec::Vec::with_capacity(size_of::<Self>());
Copy link
Contributor

@bendk bendk Jan 29, 2025

Choose a reason for hiding this comment

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

This would be a great optimization, but is size_of<Self> the right value? Our serialization code and Rust's type layout are very different. Still, maybe size_of<Self> is a good estimate -- I'm not really sure.

Can you do some tests? Like create a set of Records, Enums, strings, vecs and hashmaps, some with few fields/variants/items, some with lots of them, then compare size_of::<Self> against lower_into_rust_buffer(self).len(). I'd love to see the results of that.

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