Remove unnecessary initialization of create_id in JSON.parse()#454
Merged
hsbt merged 1 commit intoruby:masterfrom Dec 1, 2023
Merged
Remove unnecessary initialization of create_id in JSON.parse()#454hsbt merged 1 commit intoruby:masterfrom
hsbt merged 1 commit intoruby:masterfrom
Conversation
The `create_id` has no effect if `create_additions` is false. > * * *create_additions*: If set to false, the Parser doesn't create > * additions even if a matching class and create_id was found. This option > * defaults to false. https://github.com/flori/json/blob/8f7ddba3cd343c2bada3c31c9660c63f0c6df114/ext/json/ext/parser/parser.c#L1758-L1760 So, this PR will remove initialization of `create_id` when `create_additions` is false. This PR will improve JSON.parse() performance about 6%. ### Environment - MacBook Pro (16-inch, 2019) - macOS 11.1 - Intel Core i9 2.4 GHz - Ruby 2.7.2 ### Before ``` Warming up -------------------------------------- short_string_json 10.920k i/100ms long_string_json 10.326k i/100ms Calculating ------------------------------------- short_string_json 107.833k (± 1.1%) i/s - 546.000k in 5.064049s long_string_json 103.035k (± 0.9%) i/s - 516.300k in 5.011344s ``` ### After ``` Warming up -------------------------------------- short_string_json 11.654k i/100ms long_string_json 11.021k i/100ms Calculating ------------------------------------- short_string_json 115.564k (± 0.7%) i/s - 582.700k in 5.042516s long_string_json 109.216k (± 0.6%) i/s - 551.050k in 5.045726s ``` ### Test code ```ruby require 'benchmark/ips' require 'json' short_string_json = { "a" => "b" * 23, "a" * 23 => "b" }.to_json.freeze long_string_json = { "a" => "b" * 50, "a" * 50 => "b" }.to_json.freeze Benchmark.ips do |x| x.report("short_string_json") { JSON.parse(short_string_json) } x.report("long_string_json") { JSON.parse(long_string_json) } end ```
Member
|
👍 |
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Dec 1, 2023
> ruby/json#525 > Rename escape_slash in script_safe and also escape E+2028 and E+2029 Co-authored-by: Jean Boussier <[email protected]> > ruby/json#454 > Remove unnecessary initialization of create_id in JSON.parse() Co-authored-by: Watson <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
create_idhas no effect ifcreate_additionsis false.https://github.com/flori/json/blob/8f7ddba3cd343c2bada3c31c9660c63f0c6df114/ext/json/ext/parser/parser.c#L1758-L1760
So, this PR will remove initialization of
create_idwhencreate_additionsis false.This PR will improve JSON.parse() performance about 6%.
Environment
Before
After
Test code