-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parser_json: use JSON as fallback parser instead of Yajl for performance #4813
base: master
Are you sure you want to change the base?
Conversation
we are happy if we could observe micro benchmark result. |
Micro benchmarkbenchmark coderequire 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'benchmark-ips'
gem 'oj'
gem 'json'
gem 'yajl-ruby', require: 'yajl'
end
Benchmark.ips do |x|
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]]]]]]]}'
x.report('Oj.load') { Oj.load(json) }
x.report('JSON.load') { JSON.load(json) }
x.report('Yajl.load') { Yajl.load(json) }
x.compare!
end result
|
Signed-off-by: Shizuo Fujita <[email protected]>
2078284
to
9b3887f
Compare
By the way, which json gem version did you tested with? |
I tested with json v2.9.1 (latest version), it is default version in Ruby 3.4.1 If we will use Ruby 3.4 or later in the next fluent-package LTS, hmmm, I think we don't need to specify the version... |
@@ -28,12 +28,12 @@ def test_fall_back_oj_to_yajl_if_oj_not_available | |||
|
|||
result = @parser.instance.configure_json_parser(:oj) | |||
|
|||
assert_equal [Yajl.method(:load), Yajl::ParseError], result | |||
assert_equal [JSON.method(:load), JSON::ParserError], result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want JSON.method(:parse)
: https://bugs.ruby-lang.org/issues/19528
It's also very marginally faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Which issue(s) this PR fixes:
Fixes #
What this PR does / why we need it:
Recently, Ruby's json has incredible performance improvements.
It might be faster than oj gem.
So, I think json is a suitable as fallback.
This is similar with #4759
Here is easily benchmark. (I used same log file in #4759)
Before
After
config
FYI)
Docs Changes:
fluent/fluentd-docs-gitbook#560
Release Note: