Improve performance of Oj.load with symbol_keys mode#681
Merged
ohler55 merged 1 commit intoohler55:developfrom Aug 6, 2021
Merged
Improve performance of Oj.load with symbol_keys mode#681ohler55 merged 1 commit intoohler55:developfrom
Oj.load with symbol_keys mode#681ohler55 merged 1 commit intoohler55:developfrom
Conversation
Convert from String to Symbol, seems that it has some overhead. This patch will generate Symbol via `rb_intern3()` and `ID2SYM()`. The same approach seems to be favored by other gems. (https://github.com/brianmario/mysql2/blob/ca883e1a359a10f48ac5d0ce649827b424110cd7/ext/mysql2/result.c#L171-L172) − | before | after | result -- | -- | -- | -- Oj.load | 339.194k | 387.595k | 1.14x ### Environment - MacBook Air (M1, 2020) - macOS 12.0 beta 3 - Apple M1 - Ruby 3.0.2 ### Before ``` Warming up -------------------------------------- Oj.load 33.731k i/100ms Calculating ------------------------------------- Oj.load 339.194k (± 0.9%) i/s - 1.720M in 5.072086s ``` ### After ``` Warming up -------------------------------------- Oj.load 39.129k i/100ms Calculating ------------------------------------- Oj.load 387.595k (± 1.0%) i/s - 1.956M in 5.048159s ``` ### Test code ```ruby require 'benchmark/ips' require 'oj' 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('Oj.load') { Oj.load(json, symbol_keys: true) } end ```
Owner
|
Very nice, thank you. |
Collaborator
Author
|
Thank you for your quick response! |
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.
Convert from String to Symbol, seems that it has some overhead.
This patch will generate Symbol via
rb_intern3()andID2SYM().The same approach seems to be favored by other gems.
(https://github.com/brianmario/mysql2/blob/ca883e1a359a10f48ac5d0ce649827b424110cd7/ext/mysql2/result.c#L171-L172)
Environment
Before
After
Test code