Skip to content
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 is 2x-4x slower than serde-bench format #123

Closed
dtolnay opened this issue Feb 24, 2017 · 6 comments
Closed

Bincode is 2x-4x slower than serde-bench format #123

dtolnay opened this issue Feb 24, 2017 · 6 comments

Comments

@dtolnay
Copy link
Collaborator

@dtolnay dtolnay commented Feb 24, 2017

Check out cargo bench in https://github.com/serde-rs/bench. On my computer:

test bincode_deserialize ... bench:          42 ns/iter (+/- 0)
test bincode_serialize   ... bench:          82 ns/iter (+/- 1)
test serde_deserialize   ... bench:          24 ns/iter (+/- 0)
test serde_serialize     ... bench:          20 ns/iter (+/- 1)

The format is byte-for-byte identical (cargo test to confirm) so there should be no reason that Bincode would take 75% longer to deserialize and 310% longer to serialize in the SizeLimit::Infinite / &[u8] case.

In addition to all the tickets I filed today, see if you can identify other optimizations that would close this gap.

cc @maciejhirsz

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Feb 24, 2017

I would expect that endianness and the current non-trait-based size limit is responsible for most of this.

@dtolnay
Copy link
Collaborator Author

@dtolnay dtolnay commented Feb 24, 2017

Both are using big-endian. I think it's all size limit.

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Feb 26, 2017

I made a benchmarking tool here: https://github.com/TyOverby/bincode-bench

I played around with a few optimizations, and the #127 PR is twice as fast as serde-bench due to the "size-find and then pre-alloc" optimization.

Somehow this is actually faster than having an already-pre-allocated array.

bincode writer    : 334332ns 
serde-bench (ser) : 421333ns
bincode to vec    : 197910ns

Decoding is practically the same.

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Mar 2, 2017

@dtolnay: could you run your benchmark suite to confirm?

@dtolnay
Copy link
Collaborator Author

@dtolnay dtolnay commented Mar 2, 2017

I get similar results. Nice work.

@dtolnay dtolnay closed this Mar 2, 2017
@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Mar 2, 2017

🎈 🎈 🎈 🎈 🎈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.