-
-
Notifications
You must be signed in to change notification settings - Fork 272
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
bincode::serialize calls serialized_size, doubling runtime for nontrivial Serialize impls #401
Comments
Interesting that the serialize_size isn't optimized away when there is no size limit defined. I'll look into that more. The reason we have to call serialize_size is to make sure we don't accidentally cause an OOM from maliciously structured data. It might be more performant if we calculate the size as the serialization is happening. I'll try to look into it. |
Ah! I recall now, the reason that |
Unfortunately I have no idea, because I'm not a user of My only prior experience with I don't know what exactly causes |
I ran into this issue as well attempting to implement a custom serialize function for a type holding potentially gigabytes of data. We want to compress prior to serializing, and possibly chunk the data up, hence the custom serialize impl. But that's an expensive operation, so I can't afford to call serialize twice. FWIW before I found this issue, I created a minimal repro to demonstrate that In my case, I can just switch to |
Hello, |
I'm reporting this because @gbaranski noticed that JSON was faster than bincode for serializing a structure. I don't think
bincode::serialize
needs to be particularly fast, but this is quite silly. The root cause of this isbincode::serialized_size
, which (as best I can tell) fully serializes any type that isn't very simple.I'm not certain if this is the intended behavior of
SizeChecker
; on a type likechrono::DateTime
calilingbincode::serialize
will serialize the object twice. Is this itself a bug?Whether or not the speed of
serialized_size
can/should be improved, doesbincode::serialize
even need to call it? It would be nice to know the size we need ahead of time, but I really wonder if it's always faster to just callbincode::serialize_into
and maybe callVec::shrink_to_fit
after.Here's a program that demonstrates the situation:
The text was updated successfully, but these errors were encountered: