Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor internal getvalue for JSON3.Array to improve performance (#267)
* Refactor internal getvalue for JSON3.Array to improve performance Due to several 1.9 performance regressions that heavily impact JSON3, I decided to just dig in and see if we can fix in on our side since the JuliaLang changes seem pretty involved. (see issues [here](JuliaLang/julia#50762) and [here](JuliaLang/julia#48229) for context). From what I can tell, the issue really boils down to this one `getvalue` internal method on `JSON3.Array` where it was having to do some expensive "sparams" computation to instantiate the `JSON3.Array` type. By manually unrolling this method a bit and fully specifying all the type parameters this seems to resolve the performance issues. Benchmarks look like: Julia 1.8: ```julia julia> @benchmark JSON3.defaultminimum(x) BenchmarkTools.Trial: 10000 samples with 1 evaluation. Range (min … max): 31.625 μs … 140.959 μs ┊ GC (min … max): 0.00% … 0.00% Time (median): 32.250 μs ┊ GC (median): 0.00% Time (mean ± σ): 32.602 μs ± 1.562 μs ┊ GC (mean ± σ): 0.00% ± 0.00% ▂█▃▂▃ ▁▂▅██████▆▄▅▂▂▂▂▂▃▂▂▃▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂ 31.6 μs Histogram: frequency by time 36.6 μs < Memory estimate: 6.70 KiB, allocs estimate: 84. ``` Julia 1.9: ```julia julia> @benchmark JSON3.defaultminimum(x) BenchmarkTools.Trial: 10000 samples with 1 evaluation. Range (min … max): 165.584 μs … 10.519 ms ┊ GC (min … max): 0.00% … 94.46% Time (median): 168.166 μs ┊ GC (median): 0.00% Time (mean ± σ): 170.886 μs ± 103.652 μs ┊ GC (mean ± σ): 0.58% ± 0.94% ▄█▆▃ ▁▂▇████▇▇▅▄▄▄▄▃▃▂▂▂▃▃▃▄▄▃▃▃▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂ 166 μs Histogram: frequency by time 185 μs < Memory estimate: 10.11 KiB, allocs estimate: 166. ``` This PR: ```julia julia> @benchmark JSON3.defaultminimum(x) BenchmarkTools.Trial: 10000 samples with 3 evaluations. Range (min … max): 8.431 μs … 497.806 μs ┊ GC (min … max): 0.00% … 95.49% Time (median): 8.820 μs ┊ GC (median): 0.00% Time (mean ± σ): 9.157 μs ± 9.056 μs ┊ GC (mean ± σ): 1.92% ± 1.91% ▂▄▃▂ ▅██▆▄▂▁▃▅▆▅▄▃▂▂▂▂▂▂▁▁▁ ▂ ▅████▇▆██████████████████████▇▇▇▇▇▇▇▇▇▇▆▇▇▅▆▆▅▆▆▆▅▄▅▅▅▄▄▅▅▄ █ 8.43 μs Histogram: log(frequency) by time 10.8 μs < Memory estimate: 6.20 KiB, allocs estimate: 72. ``` * Remove print-related test that breaks post 1.9
- Loading branch information