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

Added FlatBuffers #7

Merged
merged 2 commits into from
Jan 22, 2019
Merged

Added FlatBuffers #7

merged 2 commits into from
Jan 22, 2019

Conversation

frol
Copy link
Contributor

@frol frol commented Jan 16, 2019

This PR is based on the PR #6.

running 19 tests
test capnp_deserialize                 ... bench:         153 ns/iter (+/- 9) = 2928 MB/s
test capnp_deserialize_packed          ... bench:         456 ns/iter (+/- 21) = 739 MB/s
test capnp_populate                    ... bench:         473 ns/iter (+/- 56)
test capnp_serialize                   ... bench:          26 ns/iter (+/- 1) = 17230 MB/s
test capnp_serialize_packed            ... bench:         392 ns/iter (+/- 67) = 859 MB/s
test clone                             ... bench:         194 ns/iter (+/- 22) = 2701 MB/s
test flatbuffers_deserialize           ... bench:           0 ns/iter (+/- 0) = 472000 MB/s
test flatbuffers_populate_with_args    ... bench:         599 ns/iter (+/- 35)
test flatbuffers_populate_with_builder ... bench:         576 ns/iter (+/- 84)
test flatbuffers_serialize             ... bench:           0 ns/iter (+/- 0) = 472000 MB/s
test rmp_serde_deserialize             ... bench:         869 ns/iter (+/- 52) = 330 MB/s
test rmp_serde_serialize               ... bench:         273 ns/iter (+/- 6) = 1051 MB/s
test rust_bincode_deserialize          ... bench:         730 ns/iter (+/- 40) = 547 MB/s
test rust_bincode_serialize            ... bench:         179 ns/iter (+/- 15) = 2234 MB/s
test rust_protobuf_deserialize         ... bench:         566 ns/iter (+/- 61) = 505 MB/s
test rust_protobuf_populate            ... bench:         350 ns/iter (+/- 54)
test rust_protobuf_serialize           ... bench:         508 ns/iter (+/- 24) = 562 MB/s
test serde_json_deserialize            ... bench:       1,402 ns/iter (+/- 942) = 431 MB/s
test serde_json_serialize              ... bench:       1,289 ns/iter (+/- 49) = 469 MB/s

test result: ok. 0 passed; 0 failed; 0 ignored; 19 measured; 0 filtered out

@erickt erickt merged commit 73c3d0c into erickt:master Jan 22, 2019
@erickt
Copy link
Owner

erickt commented Jan 22, 2019

Thanks for this!


#[bench]
fn flatbuffers_populate_with_args(b: &mut Bencher) {
let mut msg = flatbuffers::FlatBufferBuilder::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to use black_box so that it is not optimized by the compiler. If not the results might look unfair.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pickfire I have tried adding black_box and didn't change a thing at all, and since other benches didn't use black_box, I figured, I don't need them here. You have a better understanding of the topic, so it would be great if you can help and PR the suggested changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into the API. The benchmarks are just not fair that the flatbuffers return slice there. Should be something like:

#[bench]
fn flatbuffers_serialize(b: &mut Bencher) {
    let mut msg = flatbuffers::FlatBufferBuilder::new();
    let log = protocol_flatbuffers::populate_log_with_builder(&mut msg);
    msg.finish(log, None);

    let mut buf = Vec::new();

    buf.copy_from_slice(msg.finished_data());
    b.bytes = buf.len() as u64;

    b.iter(|| {
        buf.clear();
        msg.reset();
        msg.finish_minimal(log);
        buf.copy_from_slice(msg.finished_data());
    });
}

The b.iter() part should put the serialization process but not just to get the serialized data, meaning to be writing to a Vec instead of just getting the &[u8] that is processed. Any idea how the serialization part could be separated?

I tested it like above but got...

---- flatbuffers_serialize stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `472`: destination and source slices have different lengths', src/libcore/slice/mod.rs:1965:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

I feel like capnp_serialize is already incorrect as it shouldn't be faster than clone if I am correct. I hope @dtolnay can help here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, Cap'n'Proto and Flatbuffers explicitly target zero-copy on serialization and deserialization, and thus, those steps should take no time at all, just like it is the case with FlatBuffers. Basically, the data in memory is ready to be sent or read as is at any given point in time, and thus, it is "faster" than memcpy (clone), and it is unfair to include memcpy into the benchmark.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frol But the thing is that curretly flatbuffers benchmark is not fair, it does not do anything which it should do (serialization in this case).

    b.iter(|| {
        msg.finished_data()
    });

If that's the case, why not rename flatbuffers_serialize to flatbuffers_get_finished_data?


#[bench]
fn flatbuffers_populate_with_builder(b: &mut Bencher) {
let mut msg = flatbuffers::FlatBufferBuilder::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to use black_box so that it is not optimized by the compiler. If not the results might look unfair.


#[bench]
fn flatbuffers_serialize(b: &mut Bencher) {
let mut msg = flatbuffers::FlatBufferBuilder::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to use black_box so that it is not optimized by the compiler. If not the results might look unfair.


#[bench]
fn flatbuffers_deserialize(b: &mut Bencher) {
let mut msg = flatbuffers::FlatBufferBuilder::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to use black_box so that it is not optimized by the compiler. If not the results might look unfair.

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

Successfully merging this pull request may close these issues.

3 participants