romshark / jscan

High performance JSON iterator & validator for Go
BSD 3-Clause "New" or "Revised" License
89 stars 7 forks source link

perf: Reduce branching and jumps, inline number parser #20

Open romshark opened 1 year ago

romshark commented 1 year ago

Apple M1:

goos: darwin
goarch: arm64
pkg: github.com/romshark/jscan/v2
                                │   old.txt   │               new.txt               │
                                │   sec/op    │   sec/op     vs base                │
Valid/deeparray_____________-10   15.87n ± 2%   15.90n ± 1%        ~ (p=0.966 n=12)
Valid/unwind_stack__________-10   15.82n ± 3%   15.76n ± 1%        ~ (p=0.540 n=12)
Valid/miniscule_1b__________-10   11.52n ± 0%   10.38n ± 0%   -9.90% (p=0.000 n=12)
Valid/tiny_8b_______________-10   17.71n ± 0%   16.86n ± 0%   -4.83% (p=0.000 n=12)
Valid/small_336b____________-10   236.9n ± 0%   215.0n ± 0%   -9.24% (p=0.000 n=12)
Valid/large_26m_____________-10   11.10m ± 0%   11.02m ± 0%   -0.74% (p=0.000 n=12)
Valid/nasa_SxSW_2016_125k___-10   85.76µ ± 0%   76.96µ ± 0%  -10.27% (p=0.000 n=12)
Valid/escaped_3k____________-10   1.389µ ± 0%   1.304µ ± 0%   -6.08% (p=0.000 n=12)
Valid/array_int_1024_12k____-10   9.305µ ± 1%   7.253µ ± 1%  -22.05% (p=0.000 n=12)
Valid/array_dec_1024_10k____-10   9.052µ ± 0%   7.545µ ± 0%  -16.65% (p=0.000 n=12)
Valid/array_nullbool_1024_5k-10   3.584µ ± 4%   3.084µ ± 3%  -13.94% (p=0.000 n=12)
Valid/array_str_1024_639k___-10   142.5µ ± 0%   142.6µ ± 0%   +0.10% (p=0.003 n=12)
geomean                           1.724µ        1.585µ        -8.08%
romshark commented 1 year ago

Eliminating unnecessary jump in number parser:

goos: darwin
goarch: arm64
pkg: github.com/romshark/jscan/v2
                                │ large_old.txt │           large_new.txt            │
                                │    sec/op     │   sec/op     vs base               │
Valid/large_26m_____________-10     11.18m ± 0%   11.17m ± 0%  -0.14% (p=0.002 n=12)

goos: darwin
goarch: arm64
pkg: github.com/romshark/jscan/v2
                                │ arrint_old.txt │           arrint_new.txt           │
                                │     sec/op     │   sec/op     vs base               │
Valid/array_int_1024_12k____-10      9.621µ ± 1%   9.202µ ± 1%  -4.36% (p=0.000 n=12)

goos: darwin
goarch: arm64
pkg: github.com/romshark/jscan/v2
                                │ small_old.txt │           small_new.txt            │
                                │    sec/op     │   sec/op     vs base               │
Valid/small_336b____________-10     217.0n ± 0%   216.1n ± 0%  -0.39% (p=0.001 n=12)

goos: darwin
goarch: arm64
pkg: github.com/romshark/jscan/v2
                                │ nasa_old.txt │            nasa_new.txt            │
                                │    sec/op    │   sec/op     vs base               │
Valid/nasa_SxSW_2016_125k___-10    80.13µ ± 0%   79.85µ ± 0%  -0.34% (p=0.000 n=12)