Skip to content

Conversation

@ddrthall
Copy link
Contributor

Recently, Ruby's JSON has huge improvement and it is much faster. Ref. https://byroot.github.io/ruby/json/2024/12/15/optimizing-ruby-json-part-1.html

So, this PR will change yajl-ruby to Ruby's JSON.

envronment

  • Ruby: 3.4.4
  • OS: Linux 6.14.6-2
  • Compiler: gcc 15.1.1

benchmark

require 'bundler/inline'
gemfile do
  source 'https://rubygems.org'
  gem 'benchmark-ips'
  gem 'json'
  gem 'yajl-ruby'
end

require 'json'
require 'yajl'
require 'yajl/version'

puts "* JSON version: #{JSON::VERSION}"
puts "* Yajl version: #{Yajl::VERSION}"

json = '{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}'
data = JSON.parse(json)

Benchmark.ips do |x|
  x.report('Yajl.dump') { Yajl.dump(data) }
  x.report('JSON.generate') { JSON.generate(data) }

  x.compare!
end

result

$ ruby tmp.rb
* JSON version: 2.12.2
* Yajl version: 1.4.3
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-linux]
Warming up --------------------------------------
           Yajl.dump    34.964k i/100ms
       JSON.generate   120.598k i/100ms
Calculating -------------------------------------
           Yajl.dump    345.056k (± 2.8%) i/s    (2.90 μs/i) -      1.748M in   5.070452s
       JSON.generate      1.212M (± 1.6%) i/s  (824.89 ns/i) -      6.150M in   5.074868s

Comparison:
       JSON.generate:  1212286.6 i/s
           Yajl.dump:   345056.0 i/s - 3.51x  slower

What does this PR do?

A brief description of the change being made with this pull request.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Recently, Ruby's JSON has huge improvement and it is much faster.
Ref. https://byroot.github.io/ruby/json/2024/12/15/optimizing-ruby-json-part-1.html

So, this PR will change yajl-ruby to Ruby's JSON.

### envronment
- Ruby: 3.4.4
- OS: Linux 6.14.6-2
- Compiler: gcc 15.1.1

### benchmark

```ruby
require 'bundler/inline'
gemfile do
  source 'https://rubygems.org'
  gem 'benchmark-ips'
  gem 'json'
  gem 'yajl-ruby'
end

require 'json'
require 'yajl'
require 'yajl/version'

puts "* JSON version: #{JSON::VERSION}"
puts "* Yajl version: #{Yajl::VERSION}"

json = '{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}'
data = JSON.parse(json)

Benchmark.ips do |x|
  x.report('Yajl.dump') { Yajl.dump(data) }
  x.report('JSON.generate') { JSON.generate(data) }

  x.compare!
end
```

### result
```
$ ruby tmp.rb
* JSON version: 2.12.2
* Yajl version: 1.4.3
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-linux]
Warming up --------------------------------------
           Yajl.dump    34.964k i/100ms
       JSON.generate   120.598k i/100ms
Calculating -------------------------------------
           Yajl.dump    345.056k (± 2.8%) i/s    (2.90 μs/i) -      1.748M in   5.070452s
       JSON.generate      1.212M (± 1.6%) i/s  (824.89 ns/i) -      6.150M in   5.074868s

Comparison:
       JSON.generate:  1212286.6 i/s
           Yajl.dump:   345056.0 i/s - 3.51x  slower
```
@ddrthall ddrthall requested a review from a team as a code owner October 28, 2025 18:41
@ddrthall
Copy link
Contributor Author

Original MR: #73
Reopened here to allow required checks to run, as they are currently not configured to run in project forks

@ddrthall ddrthall merged commit 5710c40 into master Oct 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants