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

Initial support for serde #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

erickt
Copy link
Contributor

@erickt erickt commented Aug 13, 2015

Hello!

This PR adds initial support for serde. One of the cool things about it is that it can directly deserialize into a structure instead of having to go through cbor::Decoder to parse out a Cbor type and then deserialize from that into a cbor::RustcDecoder. It currently passes the tests and benchmarks pretty well (although it's still slower than serde_json for some unknown reason):

     Running target/release/bench-d76ac9f7d864696a

running 16 tests
test decode_medium_cbor        ... bench:  15,151,437 ns/iter (+/- 1,104,258) = 26 MB/s
test decode_medium_direct_cbor ... bench:   4,477,213 ns/iter (+/- 511,434) = 89 MB/s
test decode_medium_json        ... bench:  20,373,353 ns/iter (+/- 2,205,575) = 27 MB/s
test decode_small_cbor         ... bench:       1,315 ns/iter (+/- 37) = 30 MB/s
test decode_small_direct_cbor  ... bench:       2,558 ns/iter (+/- 345) = 15 MB/s
test decode_small_json         ... bench:       1,880 ns/iter (+/- 367) = 29 MB/s
test encode_medium_cbor        ... bench:     945,316 ns/iter (+/- 16,675) = 422 MB/s
test encode_medium_json        ... bench:   7,628,975 ns/iter (+/- 339,718) = 74 MB/s
test encode_medium_tojson      ... bench:  14,429,221 ns/iter (+/- 1,244,292) = 39 MB/s
test encode_small_cbor         ... bench:       3,460 ns/iter (+/- 359) = 11 MB/s
test encode_small_json         ... bench:         841 ns/iter (+/- 318) = 66 MB/s
test encode_small_tojson       ... bench:       1,213 ns/iter (+/- 202) = 46 MB/s
test read_medium_cbor          ... bench:   9,462,908 ns/iter (+/- 1,028,207) = 42 MB/s
test read_medium_json          ... bench:  14,876,985 ns/iter (+/- 2,433,638) = 38 MB/s
test read_small_cbor           ... bench:         785 ns/iter (+/- 193) = 50 MB/s
test read_small_json           ... bench:       1,226 ns/iter (+/- 26) = 45 MB/s

test result: ok. 0 passed; 0 failed; 0 ignored; 16 measured

     Running target/release/bench_serde-7de34a6bd2bc4f3a

running 8 tests
test deserialize_medium_cbor ... bench:   6,434,673 ns/iter (+/- 412,666) = 62 MB/s
test deserialize_medium_json ... bench:   4,808,781 ns/iter (+/- 1,297,244) = 117 MB/s
test deserialize_small_cbor  ... bench:       2,666 ns/iter (+/- 891) = 15 MB/s
test deserialize_small_json  ... bench:         439 ns/iter (+/- 16) = 127 MB/s
test serialize_medium_cbor   ... bench:   1,421,697 ns/iter (+/- 475,204) = 281 MB/s
test serialize_medium_json   ... bench:   4,730,402 ns/iter (+/- 1,666,983) = 120 MB/s
test serialize_small_cbor    ... bench:       3,479 ns/iter (+/- 491) = 11 MB/s
test serialize_small_json    ... bench:         441 ns/iter (+/- 122) = 126 MB/s

test result: ok. 0 passed; 0 failed; 0 ignored; 8 measured

     Running target/release/cbor-8d79df739e5d6e87

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

Along the way I also changed how variants are serialized. Instead of {"variant": "Name", "fields": [...]}, it's now {"Name": [...]}. This is much more efficient for serde to parse because it doesn't require potentially buffering the field argument.

Be aware though that this does add a testing dependency to serde_macros, which is currently nightly-only. Check out how serde_tests in https://githb.com/serde-rs/serde if you're interested in a method that's compatible with stable rust.

@BurntSushi
Copy link
Owner

Sorry for dropping the ball on this one. I'm definitely not keen on requiring nightly to compile cbor. I'll have to find time to look into supporting this optionally and/or pick a stable approach.

@erickt
Copy link
Contributor Author

erickt commented Sep 14, 2015

Oh I thought I wrote this patch to only require the tests to be on nightly. Silly me! I'll fix it

@DeflateAwning
Copy link

Hmm what's the state of this? Would be awesome to be able to use this!

@BurntSushi
Copy link
Owner

@DeflateAwning Please read the README.

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