Skip to content

Permit zero alloc reads #394

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

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

Conversation

lavalamp
Copy link

It's not currently possible to use jsoniter without having it allocate for each field name. This makes it possible. I found a couple existing functions that can benefit from this change, so it's overall a slight performance improvement.

benchmark                                         old ns/op     new ns/op     delta
Benchmark_encode_string_with_SetEscapeHTML-12     1373          1296          -5.61%
Benchmark_jsoniter_large_file-12                  25578         24599         -3.83%
Benchmark_json_large_file-12                      54500         54448         -0.10%
Benchmark_jsoniter_array-12                       161           162           +0.62%
Benchmark_json_array-12                           1722          1666          -3.25%
Benchmark_jsoniter_float-12                       27.8          26.1          -6.12%
Benchmark_json_float-12                           526           541           +2.85%
Benchmark_jsoniter_encode_int-12                  17.3          17.1          -1.16%
Benchmark_itoa-12                                 71.6          71.2          -0.56%
Benchmark_jsoniter_int-12                         20.8          22.0          +5.77%
Benchmark_json_int-12                             521           514           -1.34%
Benchmark_jsoniter_nested-12                      793           760           -4.16%
Benchmark_json_nested-12                          3032          2908          -4.09%
Benchmark_jsoniter_skip-12                        2075          2126          +2.46%
Benchmark_json_skip-12                            7361          7357          -0.05%

benchmark                                         old allocs     new allocs     delta
Benchmark_encode_string_with_SetEscapeHTML-12     6              6              +0.00%
Benchmark_jsoniter_large_file-12                  79             27             -65.82%
Benchmark_json_large_file-12                      14             14             +0.00%
Benchmark_jsoniter_array-12                       0              0              +0.00%
Benchmark_jsoniter_float-12                       0              0              +0.00%

benchmark                                         old bytes     new bytes     delta
Benchmark_encode_string_with_SetEscapeHTML-12     760           760           +0.00%
Benchmark_jsoniter_large_file-12                  4904          4576          -6.69%
Benchmark_json_large_file-12                      6632          6632          +0.00%
Benchmark_jsoniter_array-12                       0             0             +0.00%
Benchmark_jsoniter_float-12                       0             0             +0.00%

I added this benchmark to show the difference more clearly:

Benchmark_custom_scan/string-12                           100000             15149 ns/op            4816 B/op         76 allocs/op
Benchmark_custom_scan/bytes-12                            100000             12843 ns/op            4312 B/op          6 allocs/op

Often, users will store the field names and need to do this allocation anyway. But not always.

@codecov
Copy link

codecov bot commented Jul 26, 2019

Codecov Report

Merging #394 into master will decrease coverage by 0.44%.
The diff coverage is 69.13%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #394      +/-   ##
==========================================
- Coverage   81.81%   81.37%   -0.45%     
==========================================
  Files          41       41              
  Lines        5022     5085      +63     
==========================================
+ Hits         4109     4138      +29     
- Misses        792      819      +27     
- Partials      121      128       +7
Impacted Files Coverage Δ
iter_skip_strict.go 92.42% <100%> (ø) ⬆️
iter_str.go 85.71% <67.64%> (-5.2%) ⬇️
iter_object.go 63.08% <69.23%> (-3.4%) ⬇️
reflect_map.go 87.5% <71.42%> (ø) ⬆️
reflect_struct_decoder.go 48.74% <0%> (-0.42%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27518f6...4667787. Read the comment docs.

@lavalamp
Copy link
Author

Please let me know if this is something you're interested in, if so I can improve the coverage.

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