Optimizing Ruby’s JSON, Part 7 | byroot’s blog
24-Jan-2025 46
In the previous post, we started covering some parser optimizations. There’s just a handful more to cover until we reached what’s the state of the currently released version of ruby/json.No, the really expansive part is building the Ruby objects tree, as evidenced by the time spent in rb_hash_aset on that flame graph, but also in rb_ary_push on benchmarks that use a lot of arrays. So a custom parser can potentially end up faster overall by being better tailored to make efficient use of Ruby APIs, such as how we do unescaping inside Ruby strings to avoid extra copies and cache string keys.
But let’s focus on that part of the flame graph to see why rb_hash_aset is slow, and what we could do about it:.
Optimizing Ruby’s JSON, Part 7 | byroot’s blog #ruby #rubydeveloper #rubyonrails #Optimizing #Ruby’s #JSON, #byroot’s #blog https://rubyonrails.ba/link/optimizing-ruby-s-json-part-7-byroot-s-blog