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

A few performance improvements #263

Merged
merged 5 commits into from
Nov 4, 2018
Merged

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Nov 2, 2018

Commit 1 works around the slow dynamic dispatch that currently exist in Base (JuliaLang/julia#29887). This significantly reduces the overhead of creating the Parser:

Before:

julia> @btime JSON.parse("\"foo\"")
  3.080 μs (2 allocations: 64 bytes)
"foo"

After:

julia> @btime JSON.parse("\"foo\"")
  196.499 ns (3 allocations: 160 bytes)
"foo"

Note that quite a lot of JSON can be parsed within 3μs.

Commit 2, caches the UInt8 vector which is filled with bytes of digits. Reusing the same vector has a bunch of benefits in terms of not having to grow it over and over and the data will be hot.

Using the benchmark

julia> using Random

julia> a = string("[", join([rand(Int) for i in 1:10^3], ","), "]");

Before:

julia> @btime JSON.parse($a)
  352.473 μs (6011 allocations: 250.86 KiB)

After:

julia> @btime JSON.parse($a)
  228.998 μs (1016 allocations: 32.33 KiB)

The third commit doesn't at the moment not have much of a significant performance change but it should be strictly less work for not really more complicated code so why not? :)

constructing the error message generates quite a lot of code which makes inlining get an inaccurate view.

outlining is a simple fix and reduces the number of active basic blocks in the code from 26 to 9
@TotalVerb TotalVerb merged commit e8d39a6 into JuliaIO:master Nov 4, 2018
@KristofferC KristofferC deleted the kc/opt branch November 4, 2018 17:19
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.

3 participants