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

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

romshark
Copy link
Owner

@romshark romshark commented Aug 9, 2023

  • Remove redundant control character checks and reduce branching.
  • Remove superfluous jumps.
  • Inline number parsing and utilize lookup table.

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 romshark self-assigned this Aug 9, 2023
@romshark
Copy link
Owner Author

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)

@romshark romshark changed the title perf: Remove redundant control character checks perf: Reduce branching and jumps, inline number parser Aug 13, 2023
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