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:.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle