JSON gem optimization
2024-12
https://byroot.github.io/ruby/json/2024/12/15/optimizing-ruby-json-part-1.html
https://byroot.github.io/ruby/json/2024/12/18/optimizing-ruby-json-part-2.html
2024-10あたりからRubyのJSON gemがbyrootによって高速化され続けている
https://twitter.com/_byroot/status/1849382128565244211
By the way, if you got some realistic benchmarks in which JSON.dump is significantly slower than an alternative gem, please let me know.
As long as it's not the result of the alternative doing something incorrect, I'll consider it as a bug.
https://github.com/ruby/json/pull/670
文字列のエスケープ不要時には行わない
余計なコピーが起きないだけでなく、大きい文字列のときはmalloc / freeのコストも下がる
https://github.com/ruby/json/pull/671
バッファにコピーしてエスケープを解除し、そのバッファを最終文字列にコピーするのではなく、最終文字列に直接コピーすることができる
https://github.com/ruby/json/pull/673
https://github.com/ruby/json/pull/675
https://github.com/ruby/json/pull/676
2.8.0
JSON.parse と JSON.loadが最大1.7倍
https://github.com/ruby/json/releases/tag/v2.8.0