Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Conversation

@markbt
Copy link

@markbt markbt commented Jan 31, 2023

Hi bincode developers. This is the second in a series of 3 PRs that would allow us to replace our current use of Abomonation with bincode, without a noticeable performance hit. We'd like these to be adopted upstream, and hope they are useful for other users of bincode also.

We use SmallVec in a number of places in the structures that we serialize, as this gives us a noticeable memory footprint and performance improvement. Rust's orphan rule prevents us from implementing the bincode traits for SmallVec ourselves, as it's defined in a different crate. Instead, we propose adding a new optional feature to bincode with implements the traits for that type when enabled. When the smallvec feature is specified, bincode additionally provides implementations of Encode and Decode for SmallVec, much like it already does for the standard library types.

When the `smallvec` features is specified, implementations of `Encode` and `Decode` for `SmallVec` from the `smallvec` crate will be provided.
@VictorKoenders
Copy link
Contributor

Ideally we would want to have other crates implement bincode, instead of bincode implementing all of the crates in the rust ecosystem.

Have you tried using #[bincode(with_serde)] as described here? I wonder if that will give an ergonomic-enough API for you to work with.

We'll run into issues when we finally release bincode 2.0 and other crates are thinking of implementing bincode in their crate, but bincode also provides an implementation. I think if we are going to accept features like this, they should be obviously marked that they can be removed at any time, e.g. smallvec-unstable. We'll reserve the right to remove those at any point in the future.

@markbt
Copy link
Author

markbt commented Feb 2, 2023

Using #[bincode(with_serde)] is about a 5-10% perf regression, so I'd rather not do that if it can be avoided. If the preferred mode is for other crates to implement your traits, then I will see if the smallvec developers will accept a small PR to add support for bincode there.

@markbt
Copy link
Author

markbt commented Feb 17, 2023

Smallvec will accept my change there once bincode 2.0 is released, so I will close this PR shortly. Do you know when a 2.0 release is likely?

@VictorKoenders
Copy link
Contributor

Unfortunately both ZoeyR and I have been very busy so it might be a while. We'll need to fix all the issues labeled as "bincode 2" and then I think we should be able to launch

@stale
Copy link

stale bot commented Apr 19, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants