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

Reduce allocations by pooling buffered JSON objects #622

Merged
merged 1 commit into from
Nov 25, 2020

Conversation

markusthoemmes
Copy link
Contributor

@markusthoemmes markusthoemmes commented Nov 25, 2020

As per title. Streams and iterators allocate a buffer to work internally, which can be reused. This does that.

The pool provided by jsoniter doesn't seem to fit our use-case, as it assumes to be passed a byte slice to read from rather than a reader.

Signed-off-by: Markus Thömmes [email protected]

Benchmark

benchmark                                                                                       old ns/op     new ns/op     delta
BenchmarkUnmarshal/data,_attributes_and_extensions_and_specversion_with_struct_data_v1.0-16     19402         18523         -4.53%
BenchmarkUnmarshal/base64_json_encoded_data_v1.0-16                                             11628         11660         +0.28%
BenchmarkUnmarshal/nil_data_v1.0-16                                                             16632         16376         -1.54%
BenchmarkUnmarshal/struct_data_v0.3-16                                                          18055         17013         -5.77%
BenchmarkUnmarshal/string_data_v0.3-16                                                          17674         16862         -4.59%
BenchmarkUnmarshal/struct_data_v1.0-16                                                          17987         17145         -4.68%
BenchmarkUnmarshal/string_data_v1.0-16                                                          17275         16460         -4.72%
BenchmarkUnmarshal/base64_xml_encoded_data_v1.0-16                                              12242         12249         +0.06%
BenchmarkUnmarshal/nil_data_v0.3-16                                                             15156         14909         -1.63%
BenchmarkUnmarshal/data,_attributes_and_extensions_and_specversion_with_struct_data_v0.3-16     19147         18010         -5.94%

benchmark                                                                                       old allocs     new allocs     delta
BenchmarkUnmarshal/data,_attributes_and_extensions_and_specversion_with_struct_data_v1.0-16     87             83             -4.60%
BenchmarkUnmarshal/base64_json_encoded_data_v1.0-16                                             51             49             -3.92%
BenchmarkUnmarshal/nil_data_v1.0-16                                                             73             71             -2.74%
BenchmarkUnmarshal/struct_data_v0.3-16                                                          78             76             -2.56%
BenchmarkUnmarshal/string_data_v0.3-16                                                          77             75             -2.60%
BenchmarkUnmarshal/struct_data_v1.0-16                                                          76             74             -2.63%
BenchmarkUnmarshal/string_data_v1.0-16                                                          75             73             -2.67%
BenchmarkUnmarshal/base64_xml_encoded_data_v1.0-16                                              51             49             -3.92%
BenchmarkUnmarshal/nil_data_v0.3-16                                                             73             71             -2.74%
BenchmarkUnmarshal/data,_attributes_and_extensions_and_specversion_with_struct_data_v0.3-16     87             83             -4.60%

benchmark                                                                                       old bytes     new bytes     delta
BenchmarkUnmarshal/data,_attributes_and_extensions_and_specversion_with_struct_data_v1.0-16     6024          3739          -37.93%
BenchmarkUnmarshal/base64_json_encoded_data_v1.0-16                                             3874          2708          -30.10%
BenchmarkUnmarshal/nil_data_v1.0-16                                                             4518          3352          -25.81%
BenchmarkUnmarshal/struct_data_v0.3-16                                                          4750          3584          -24.55%
BenchmarkUnmarshal/string_data_v0.3-16                                                          4734          3568          -24.63%
BenchmarkUnmarshal/struct_data_v1.0-16                                                          4574          3408          -25.49%
BenchmarkUnmarshal/string_data_v1.0-16                                                          4558          3392          -25.58%
BenchmarkUnmarshal/base64_xml_encoded_data_v1.0-16                                              3890          2725          -29.95%
BenchmarkUnmarshal/nil_data_v0.3-16                                                             4518          3352          -25.81%
BenchmarkUnmarshal/data,_attributes_and_extensions_and_specversion_with_struct_data_v0.3-16     6024          3739          -37.93%

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

Successfully merging this pull request may close these issues.

2 participants