Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of
Oj.load
with symbol_keys mode (#681)
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 ```
- Loading branch information
1 parent
2f8cf2b
commit 62aea59
Showing
4 changed files
with
22 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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