Closed
Conversation
This patch introduces functions same as rb_hash_has_key()
to reduce rb_funcall() calling because it has a overhead.
− | before | after | result
-- | -- | -- | --
JSON.parse | 302.109k | 343.547k | 1.14x
JSON.generate | 569.705k | 568.668k | −
### Environment
- MacBook Air (M1, 2020)
- macOS 12.0 beta
- Apple M1
- Ruby 3.0.2
### Before
```
Warming up --------------------------------------
JSON.parse 30.347k i/100ms
JSON.generate 56.987k i/100ms
Calculating -------------------------------------
JSON.parse 302.109k (± 0.2%) i/s - 1.517M in 5.022546s
JSON.generate 569.705k (± 0.2%) i/s - 2.849M in 5.001462s
```
### After
```
Warming up --------------------------------------
JSON.parse 35.109k i/100ms
JSON.generate 57.611k i/100ms
Calculating -------------------------------------
JSON.parse 343.547k (± 0.3%) i/s - 1.720M in 5.007637s
JSON.generate 568.668k (± 0.3%) i/s - 2.881M in 5.065486s
```
### Test code
```ruby
require 'benchmark/ips'
require 'json'
json =<<-EOF
{
"$id": "https://example.com/person.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string",
"description": "The person's first name."
},
"lastName": {
"type": "string",
"description": "The person's last name."
},
"age": {
"description": "Age in years which must be equal to or greater than zero.",
"type": "integer",
"minimum": 0
}
}
}
EOF
Benchmark.ips do |x|
x.report('JSON.parse') { JSON.parse(json, symbolize_names: true) }
data = JSON.parse(json, symbolize_names: true)
x.report('JSON.generate') { JSON.generate(json, indent: "\t") }
end
```
Member
|
Superseeded by: #622 Thank you. |
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.
This patch introduces functions same as rb_hash_has_key()
to reduce rb_funcall() calling because it has a overhead.
Environment
Before
After
Test code