-
Notifications
You must be signed in to change notification settings - Fork 33
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
Switch from bincode to postcard #410
Conversation
Hm... Statistic test says that we consume one more byte 🤔 I will investigate tomorrow, I didn't expect it. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #410 +/- ##
==========================================
- Coverage 89.75% 89.47% -0.29%
==========================================
Files 51 53 +2
Lines 2773 2793 +20
==========================================
+ Hits 2489 2499 +10
- Misses 284 294 +10 ☔ View full report in Codecov by Sentry. |
@UkoeHB I looked into the difference. I forgot that we used variable integer encoding for update indices and switched them to fixints in this PR. But I think it's good for the same reason we made ticks use fixints. What do you think? If you agree, then the PR is ready for review. |
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.
The implicit varint encoding is a bit confusing since you can't infer it from the callsite.
Co-authored-by: UkoeHB <[email protected]>
I agree! What do you think about the tick? Do you agree about with turning into varint? |
Do you mean the update indices being fixed int? It is fine yes. |
No, no, I mean the
It's because it uses |
Ah ok, yes we can switch to varints for u32 ticks. |
I recently discovered that deserialization from
std::io::Cursor
allocates because it needs a temporary buffer to read data into. Here is whatbincode
uses.RC version of bincode provides a special Reader additionally to read from it. Unfortunately, I don't think bincode will be released soon, see this comment.
This is why I decided to try
postcard
. Difference frombincode
postcard
API more.DefaultOptions::new()
frombincode
was always seemed off to me. In the latest RC they pass settings to each call which is even more verbose.postcard
have a very flexible Flavor system.no_std
. Although, RC version of bincode also supports it.postcard::Error
is not an alias for a boxed error, similar tobincode
RC.I compered the perfomance, we didn't get any improvements in our benchmarks, it's within the margin. But I think it's worth to switch.
To get
postcard
play nicely with streaming ser/de, I added Flavors and functions similar to whatpostcard
provides.ExtendFlavorMut
, which is similar to the providedExtendFlavor
, but accepts value by reference.BufFlavor
which works with any type that implementsbytes::Buf
. This allows me to read fromBytes
directly without extra allocations or manually reassigning the value like with built-inSliceFlavor
. I re-exportedBytes
from the crate.I also created a newtype for mutation indexes to mark it as fixint-serializable with
postcard
.Since we have more suited variable integers, it might worth to discuss using varints for ticks. Previously, ticks started to use 5 bytes after 2^16 (which happens after ~18 minutes with 60 ticks/s).
But right now it's after 2^28 and with 60 ticks/s it starts to take 5 bytes after ~51 day.
If you agree, I will push it as a follow-up PR. This PR only swaps the API without any logical changes.