Skip to content

Commit bfb7797

Browse files
committed
Elide JSON::Parser allocation
Similar to #662, but here we don't even need to spill on the heap, because the parser is never exposed. Before: ``` == Parsing small hash (65 bytes) ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [arm64-darwin23] Warming up -------------------------------------- json 188.233k i/100ms oj 213.985k i/100ms oj strict 242.564k i/100ms Oj::Parser 448.682k i/100ms rapidjson 291.925k i/100ms Calculating ------------------------------------- json 1.983M (± 0.5%) i/s (504.32 ns/i) - 9.976M in 5.031352s oj 2.334M (± 0.2%) i/s (428.48 ns/i) - 11.769M in 5.042839s oj strict 2.689M (± 0.2%) i/s (371.85 ns/i) - 13.584M in 5.051044s Oj::Parser 4.662M (± 1.2%) i/s (214.50 ns/i) - 23.331M in 5.005414s rapidjson 3.110M (± 0.7%) i/s (321.57 ns/i) - 15.764M in 5.069531s Comparison: json: 1982878.1 i/s Oj::Parser: 4661924.8 i/s - 2.35x faster rapidjson: 3109722.2 i/s - 1.57x faster oj strict: 2689277.0 i/s - 1.36x faster oj: 2333852.9 i/s - 1.18x faster ``` After: ``` == Parsing small hash (65 bytes) ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [arm64-darwin23] Warming up -------------------------------------- json 223.083k i/100ms oj 214.400k i/100ms oj strict 243.519k i/100ms Oj::Parser 445.445k i/100ms rapidjson 293.936k i/100ms Calculating ------------------------------------- json 2.279M (± 4.5%) i/s (438.71 ns/i) - 11.377M in 5.002132s oj 2.315M (± 0.3%) i/s (431.96 ns/i) - 11.578M in 5.001141s oj strict 2.665M (± 0.9%) i/s (375.19 ns/i) - 13.394M in 5.025562s Oj::Parser 4.703M (± 0.3%) i/s (212.63 ns/i) - 23.609M in 5.019913s rapidjson 3.129M (± 0.4%) i/s (319.55 ns/i) - 15.873M in 5.072213s Comparison: json: 2279385.2 i/s Oj::Parser: 4703032.3 i/s - 2.06x faster rapidjson: 3129356.1 i/s - 1.37x faster oj strict: 2665318.3 i/s - 1.17x faster oj: 2315009.3 i/s - same-ish: difference falls within error ```
1 parent dc19b2f commit bfb7797

File tree

6 files changed

+520
-326
lines changed

6 files changed

+520
-326
lines changed

0 commit comments

Comments
 (0)