-
Notifications
You must be signed in to change notification settings - Fork 108
Slightly improved serialization size estimation #3629
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
base: main
Are you sure you want to change the base?
Conversation
|
||
pub fn encode_as_bilrost<T: bilrost::Message>(value: &T) -> Bytes { | ||
let buf = value.encode_fast(); | ||
let buf = value.encode_contiguous(); |
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.
This is to ensure that into_vec() and Bytes::from() are zero-cost operations.
This has been causing memory leak if it's set to zero so we are removing and it can be later re-introduced if its underlying issues are fixed.
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.
Changes looks good to me. Thank you so much. I only left one comment/question
Ok(()) | ||
} | ||
|
||
fn estimate_json_serde_len<T: Serialize>(value: &T) -> Result<usize, serde_json::error::Error> { |
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.
Wouldn't this make calculating the estimate_size as inefficient as actually serialising the type (plus the buf allocations).
In other words, how is that better than just serialising the value directly without knowing the size estimate before hand.
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.
it's not really serializing, it's just performing all the visits needed to serialize.
Stack created with Sapling. Best reviewed with ReviewStack.