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

feat: improve Decoder string unescaping performance #446

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

orisano
Copy link
Sponsor Contributor

@orisano orisano commented Mar 25, 2023

before

goos: darwin
goarch: arm64
pkg: benchmark
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2396	    501217 ns/op	  610443 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2370	    506517 ns/op	  635933 B/op	   10006 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2365	    500938 ns/op	  612078 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2216	    508809 ns/op	  643572 B/op	   10006 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2354	    505128 ns/op	  621201 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2235	    506122 ns/op	  631196 B/op	   10006 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2334	    501138 ns/op	  611282 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2360	    501009 ns/op	  609720 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2343	    505980 ns/op	  608884 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2362	    504268 ns/op	  614357 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      94	  12573430 ns/op	  586036 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      96	  12545696 ns/op	  586047 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      93	  12660176 ns/op	  591675 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      85	  12624620 ns/op	  586036 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      94	  12561482 ns/op	  591631 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      94	  12597026 ns/op	  586034 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      93	  12598319 ns/op	  586040 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      93	  12613099 ns/op	  586039 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      94	  12589107 ns/op	  597210 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      96	  12599589 ns/op	  586044 B/op	   10014 allocs/op

after

goos: darwin
goarch: arm64
pkg: benchmark
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2396	    500616 ns/op	  615926 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2367	    508130 ns/op	  632242 B/op	   10006 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2360	    507290 ns/op	  622408 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2344	    503449 ns/op	  612675 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2325	    505496 ns/op	  617994 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2314	    504651 ns/op	  611184 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2290	    507516 ns/op	  615741 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2355	    514382 ns/op	  618502 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2136	    509533 ns/op	  617787 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2216	    507166 ns/op	  612041 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2430	    489476 ns/op	  586677 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2415	    527139 ns/op	  588856 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2358	    489797 ns/op	  586700 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2437	    487946 ns/op	  586247 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2415	    488028 ns/op	  586901 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2430	    490985 ns/op	  586895 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2421	    488670 ns/op	  586898 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2419	    487473 ns/op	  586249 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2406	    489513 ns/op	  586686 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2380	    493454 ns/op	  586254 B/op	   10014 allocs/op

benchstat

goos: darwin
goarch: arm64
pkg: benchmark
                                                     │   ./old.txt   │              ./new.txt              │
                                                     │    sec/op     │   sec/op     vs base                │
_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12     504.7µ ± 1%   507.2µ ± 1%        ~ (p=0.123 n=10)
_Decode_LargeSlice_EscapedString_GoJson/Decode-12      12597.7µ ± 0%   489.5µ ± 1%  -96.11% (p=0.000 n=10)
geomean                                                  2.522m        498.3µ       -80.24%

                                                     │  ./old.txt   │              ./new.txt              │
                                                     │     B/op     │     B/op      vs base               │
_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12   598.8Ki ± 4%   602.4Ki ± 1%       ~ (p=0.631 n=10)
_Decode_LargeSlice_EscapedString_GoJson/Decode-12      572.3Ki ± 1%   572.9Ki ± 0%       ~ (p=0.138 n=10)
geomean                                                585.4Ki        587.5Ki       +0.35%

                                                     │  ./old.txt  │              ./new.txt               │
                                                     │  allocs/op  │  allocs/op   vs base                 │
_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12   10.01k ± 0%   10.01k ± 0%       ~ (p=0.582 n=10)
_Decode_LargeSlice_EscapedString_GoJson/Decode-12      10.01k ± 0%   10.01k ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                10.01k        10.01k       +0.00%
¹ all samples are equal

@codecov-commenter
Copy link

codecov-commenter commented Mar 25, 2023

Codecov Report

Merging #446 (0c2acb8) into master (7be58ac) will decrease coverage by 0.31%.
The diff coverage is 78.28%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #446      +/-   ##
==========================================
- Coverage   77.08%   76.78%   -0.31%     
==========================================
  Files          55       55              
  Lines       18830    19011     +181     
==========================================
+ Hits        14516    14597      +81     
- Misses       3679     3762      +83     
- Partials      635      652      +17     

@orisano orisano force-pushed the feat/improve-performance-escape-string-stream branch 4 times, most recently from da4b1bb to 02e2b6b Compare March 25, 2023 19:00
before
goos: darwin
goarch: arm64
pkg: benchmark
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2396	    501217 ns/op	  610443 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2370	    506517 ns/op	  635933 B/op	   10006 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2365	    500938 ns/op	  612078 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2216	    508809 ns/op	  643572 B/op	   10006 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2354	    505128 ns/op	  621201 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2235	    506122 ns/op	  631196 B/op	   10006 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2334	    501138 ns/op	  611282 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2360	    501009 ns/op	  609720 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2343	    505980 ns/op	  608884 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2362	    504268 ns/op	  614357 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      94	  12573430 ns/op	  586036 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      96	  12545696 ns/op	  586047 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      93	  12660176 ns/op	  591675 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      85	  12624620 ns/op	  586036 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      94	  12561482 ns/op	  591631 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      94	  12597026 ns/op	  586034 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      93	  12598319 ns/op	  586040 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      93	  12613099 ns/op	  586039 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      94	  12589107 ns/op	  597210 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	      96	  12599589 ns/op	  586044 B/op	   10014 allocs/op

after
goos: darwin
goarch: arm64
pkg: benchmark
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2396	    500616 ns/op	  615926 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2367	    508130 ns/op	  632242 B/op	   10006 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2360	    507290 ns/op	  622408 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2344	    503449 ns/op	  612675 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2325	    505496 ns/op	  617994 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2314	    504651 ns/op	  611184 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2290	    507516 ns/op	  615741 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2355	    514382 ns/op	  618502 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2136	    509533 ns/op	  617787 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Unmarshal-12         	    2216	    507166 ns/op	  612041 B/op	   10005 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2430	    489476 ns/op	  586677 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2415	    527139 ns/op	  588856 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2358	    489797 ns/op	  586700 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2437	    487946 ns/op	  586247 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2415	    488028 ns/op	  586901 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2430	    490985 ns/op	  586895 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2421	    488670 ns/op	  586898 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2419	    487473 ns/op	  586249 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2406	    489513 ns/op	  586686 B/op	   10014 allocs/op
Benchmark_Decode_LargeSlice_EscapedString_GoJson/Decode-12            	    2380	    493454 ns/op	  586254 B/op	   10014 allocs/op
@orisano orisano force-pushed the feat/improve-performance-escape-string-stream branch from 02e2b6b to 0c2acb8 Compare March 26, 2023 12:39
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.

None yet

2 participants