Commit ed03e0e
authored
Optimize parsing option args in
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 #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
```JSON.parse (#720)1 parent a4efd89 commit ed03e0e
1 file changed
+47
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
502 | 548 | | |
503 | 549 | | |
504 | 550 | | |
| |||
524 | 570 | | |
525 | 571 | | |
526 | 572 | | |
527 | | - | |
528 | | - | |
529 | 573 | | |
530 | 574 | | |
531 | 575 | | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | 576 | | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
| 577 | + | |
580 | 578 | | |
581 | 579 | | |
582 | 580 | | |
| |||
0 commit comments