refactor: replace unmaintained bincode with postcard + borsh - #1302
Open
MrCroxx wants to merge 5 commits into
Open
refactor: replace unmaintained bincode with postcard + borsh#1302MrCroxx wants to merge 5 commits into
MrCroxx wants to merge 5 commits into
Conversation
MrCroxx
force-pushed
the
refactor/replace-bincode-with-postcard-and-borsh
branch
2 times, most recently
from
June 16, 2026 15:43
f41547b to
31a92de
Compare
Codecov Report❌ Patch coverage is
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Replace the unmaintained `bincode` (RUSTSEC-2025-0141) dependency with two actively maintained serialization backends behind feature gates: - `serde` feature: uses `postcard`, a community-standard serde-native binary format. Drop-in replacement for the old bincode-backed blanket `Code` impl. - `borsh` feature (NEW): uses NEAR Protocol `borsh`, a high-performance binary serialization with its own trait system. Takes priority over the `serde` feature when both are enabled to avoid coherence conflicts. Feature precedence: `borsh` > `serde` (postcard) > manual impls. The benchmark has been rewritten to directly compare postcard, borsh, and manual encoding across three payload sizes (64B, 1KB, 64KB). Signed-off-by: MrCroxx <mrcroxx.cs@gmail.com>
Signed-off-by: MrCroxx <mrcroxx.cs@gmail.com>
Signed-off-by: MrCroxx <mrcroxx.cs@gmail.com>
Signed-off-by: MrCroxx <mrcroxx.cs@gmail.com>
MrCroxx
force-pushed
the
refactor/replace-bincode-with-postcard-and-borsh
branch
from
June 16, 2026 16:01
57235c7 to
f3eca19
Compare
Signed-off-by: MrCroxx <mrcroxx.cs@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the unmaintained
bincodecrate (RUSTSEC-2025-0141) with two actively maintained serialization backends behind feature gates.Changes
Dependencies
bincode = "1"(workspace)postcard = "1"(serde-native, community standard replacement)borsh = { version = "1", features = ["derive"] }(NEAR Protocol, high performance)Feature Gates
Codeimplbool,Vec<u8>,String,Bytesserdeonlyimpl Code for T: Serialize + DeserializeOwnedviapostcardborshonlyimpl Code for T: BorshSerialize + BorshDeserializeviaborshserde+borshModified Files
Cargo.toml— workspace depsfoyer-common/Cargo.toml— features and dependenciesfoyer-common/src/code.rs— three mutually exclusiveCodeimpl paths with#[cfg]foyer-common/src/error.rs—bincode_error()->postcard_error()foyer/Cargo.toml— addborshpass-through featureexamples/Cargo.toml— addborshpass-through featureNew Benchmark
foyer-common/benches/bench_serde/rewritten to directly compare postcard, borsh, and manual encoding:#[cfg(feature = "serde")])#[cfg(feature = "borsh")])Benchmark Results
Test machine: Linux 6.8, 100 samples per benchmark, 3s warmup.
Test data:
struct Entry { id: u64, label: String, payload: Vec<u8> }Encode
Decode
Encoded Size (raw = id + label + payload)
Key Findings
memcpyfor both encode and decode across all sizesmemcpyMigration Notes
Error::bincode_error()has been replaced withError::postcard_error()(available when theserdefeature is active andborshis not).Serialize + DeserializeOwnedforCodecontinue to work with theserdefeature, no code changes needed.borshfeature and deriveBorshSerialize + BorshDeserialize.Generated with Claude Code