Open mame opened 9 months ago
Note: I got oj-bench.rb
from this article.
I will re-run https://github.com/flori/json/actions/runs/7336797514/job/19976695584?pr=562 after supporting Ruby 3.3 at ruby/setup-ruby
.
I'd love to see this merged, @hsbt could you take another look now that Ruby 3.3 is properly released?
This PR speeds up
JSON.generate
by approximately 1.75x (485k instructions per second -> 840k instructions per second) for the benchmark of Oj. This makesJSON.generate
nearly as fast asOj.dump
.Before:
After:
This PR consists of the following several improvements.
Drop prebuild of
array_delim
, etc.array_delim
is usually a single comma character. Usingmemcpy
to copy a single character was inefficient.array_nl
separately without prebuild.Use faster Ruby API for encoding checks.
Use a fast path when string escaping is not needed.
Use faster Ruby API for dispatching the class of objects.
Use
generate_json_string
for object keys.generate_json
in general dispatch was an unnecessary overhead.Use faster Ruby API for reading array elements.
I made them into one PR because I thought separating this to multiple PRs would bring many conflicts between PRs. However, if you want me to do so, feel free to let me know.