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

Performance comparison with in-place serde + possible improvements #6

Closed
ncpenke opened this issue Jun 12, 2022 · 2 comments
Closed

Comments

@ncpenke
Copy link
Contributor

ncpenke commented Jun 12, 2022

Awesome work as usual @jorgecarleitao.

I was curious what the performance would be with serde_json's in-place deserialization so I created a custom deserializer for parser::Value. I had to duplicate parser::Value to use converted numbers since it wasn't possible to use this library's lazy numeric parser without replicating all of serde_json's parsing code.

The code for the custom deserializer is here. I updated the benchmarks to include this implementation, and also added a test for escaped strings.

Results from my macbook are below. serde_json_custom is the benchmark for the custom deserializer. string_escaped_chars is the benchmark for escaped strings.

string json_deserializer 2^10 time:   [63.949 us 64.339 us 64.739 us]
string serde_json 2^10  time:   [100.51 us 101.21 us 101.94 us]
string serde_json_custom 2^10 time:   [41.162 us 41.491 us 41.923 us]
string simd_json 2^10   time:   [25.250 us 25.574 us 25.932 us]
string_escaped_chars json_deserializer 2^10 time:   [193.93 us 195.39 us 196.92 us]
string_escaped_chars serde_json 2^10 time:   [130.26 us 131.22 us 132.27 us]
string_escaped_chars serde_json_custom 2^10 time:   [137.42 us 138.47 us 139.55 us]
string_escaped_chars simd_json 2^10 time:   [46.427 us 46.821 us 47.252 us]

I was surprised at the results, especially since nothing stuck out from inspecting the code. So I dug in further and it seems to come to the relatively large match expression in compute_length. Reworking it improved up the numbers:

string json_deserializer 2^10 time:   [39.574 us 39.719 us 39.868 us]
string serde_json 2^10  time:   [103.74 us 104.84 us 105.99 us]
string serde_json_custom 2^10 time:   [46.926 us 48.188 us 49.584 us]
string simd_json 2^10   time:   [27.517 us 27.786 us 28.105 us]
string_escaped_chars json_deserializer 2^10 time:   [144.19 us 145.30 us 146.43 us]
string_escaped_chars serde_json 2^10 time:   [143.75 us 144.64 us 145.52 us]
string_escaped_chars serde_json_custom 2^10 time:   [145.71 us 147.09 us 148.73 us]
string_escaped_chars simd_json 2^10 time:   [47.152 us 47.652 us 48.162 us]

If you're able to replicate the results and interested in taking the changes can open a PR. Changes are in this branch. Thanks!

@jorgecarleitao
Copy link
Owner

Thanks!

Great comparison and analysis, @ncpenke , very well though through.

interested in taking the changes can open a PR

Yes! That would be awesome!

I think that it would also be valuable to have the code from the branch implementing Deserialize under a serde feature flag. I am thinking doing the same for the trait Value as discussed in #3

@ncpenke
Copy link
Contributor Author

ncpenke commented Jun 12, 2022

I think that it would also be valuable to have the code from the branch implementing Deserialize under a serde feature flag

Sounds great! I can make those as part of another pass.

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

No branches or pull requests

2 participants