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

json: improve performance by using a pool of scanners #535

Merged
merged 3 commits into from
May 26, 2024
Merged

Conversation

gabriel-vasile
Copy link
Owner

goos: linux
goarch: amd64
pkg: github.com/gabriel-vasile/mimetype
cpu: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
                                              │   master    │             sync_pool              │
                                              │   sec/op    │   sec/op     vs base               │
Files/json.json/application/json-8              1.403µ ± 0%   1.355µ ± 1%  -3.39% (p=0.000 n=20)
Files/ndjson.xl.ndjson/application/x-ndjson-8   8.655µ ± 1%   8.504µ ± 1%  -1.76% (p=0.001 n=20)
Files/ndjson.ndjson/application/x-ndjson-8      3.069µ ± 1%   2.958µ ± 5%       ~ (p=0.129 n=20)
geomean                                         3.340µ        3.242µ       -2.92%

                                              │   master   │               sync_pool               │
                                              │    B/op    │   B/op    vs base                     │
Files/json.json/application/json-8              120.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=20)
Files/ndjson.xl.ndjson/application/x-ndjson-8   720.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=20)
Files/ndjson.ndjson/application/x-ndjson-8      240.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=20)
geomean                                         274.7                  ?                       ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean

                                              │   master   │                sync_pool                │
                                              │ allocs/op  │ allocs/op   vs base                     │
Files/json.json/application/json-8              4.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=20)
Files/ndjson.xl.ndjson/application/x-ndjson-8   24.00 ± 0%    0.00 ± 0%  -100.00% (p=0.000 n=20)
Files/ndjson.ndjson/application/x-ndjson-8      8.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=20)
geomean                                         9.158                    ?                       ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean

it helps by reducing memory allocations to amortized 0
➜  mimetype git:(bench) ✗ benchstat master sync_pool
goos: linux
goarch: amd64
pkg: github.com/gabriel-vasile/mimetype
cpu: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
                                              │   master    │             sync_pool              │
                                              │   sec/op    │   sec/op     vs base               │
Files/json.json/application/json-8              1.403µ ± 0%   1.355µ ± 1%  -3.39% (p=0.000 n=20)
Files/ndjson.xl.ndjson/application/x-ndjson-8   8.655µ ± 1%   8.504µ ± 1%  -1.76% (p=0.001 n=20)
Files/ndjson.ndjson/application/x-ndjson-8      3.069µ ± 1%   2.958µ ± 5%       ~ (p=0.129 n=20)
geomean                                         3.340µ        3.242µ       -2.92%

                                              │   master   │               sync_pool               │
                                              │    B/op    │   B/op    vs base                     │
Files/json.json/application/json-8              120.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=20)
Files/ndjson.xl.ndjson/application/x-ndjson-8   720.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=20)
Files/ndjson.ndjson/application/x-ndjson-8      240.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=20)
geomean                                         274.7                  ?                       ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean

                                              │   master   │                sync_pool                │
                                              │ allocs/op  │ allocs/op   vs base                     │
Files/json.json/application/json-8              4.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=20)
Files/ndjson.xl.ndjson/application/x-ndjson-8   24.00 ± 0%    0.00 ± 0%  -100.00% (p=0.000 n=20)
Files/ndjson.ndjson/application/x-ndjson-8      8.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=20)
geomean                                         9.158                    ?                       ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean
there is no reason to make it concurrent
@gabriel-vasile gabriel-vasile merged commit 09ff708 into master May 26, 2024
5 checks passed
@gabriel-vasile gabriel-vasile deleted the bench branch May 26, 2024 15:04
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.

1 participant