Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize parsing option args in
JSON.parse
This PR will optimize the parsing options in `JSON.parse`. It looked up one by one to make sure that the supported options were included in passed options. This approach of looking up the passed hash each time has an overhead. This PR will apply the same changing as ohler55#683 − | before | after | result -- | -- | -- | -- Oj.dump | 518.709k | 528.462k | 1.019x ### Environment - MacBook Pro (M1 Max, 2021) - macOS 12.0 - Apple M1 Max - Ruby 3.0.2 ### Before ``` Warming up -------------------------------------- JSON.parse 51.973k i/100ms Calculating ------------------------------------- JSON.parse 518.709k (± 0.3%) i/s - 5.197M in 10.019799s ``` ### After ``` Warming up -------------------------------------- JSON.parse 52.534k i/100ms Calculating ------------------------------------- JSON.parse 528.462k (± 0.5%) i/s - 5.306M in 10.040606s ``` ### 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.warmup = 10 x.time = 10 Oj.mimic_JSON x.report('JSON.parse') { JSON.parse(json, symbolize_names: true) } end ```
- Loading branch information