Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch will sort the conditional statements to reduce the conditional branches by skipping if statements that do not need to be executed depending on the value of `first`. − | before | after | result -- | -- | -- | -- Oj.load | 325.594k | 341.356k | 1.048x ### Environment - Linux - Manjaro Linux x86_64 - Kernel: 6.12.4-1-MANJARO - AMD Ryzen 9 8945HS - gcc version 14.2.1 - Ruby 3.4.1 ### Code ```ruby require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'benchmark-ips' gem 'oj' end json = '{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}' Benchmark.ips do |x| x.time = 10 x.report('Oj.load compat') { Oj.load(json, mode: :compat) } end ``` ### Before ``` $ ruby json_load.rb ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] Warming up -------------------------------------- Oj.load compat 32.352k i/100ms Calculating ------------------------------------- Oj.load compat 325.594k (± 1.8%) i/s (3.07 μs/i) - 3.268M in 10.039265s ``` ### After ``` $ ruby json_load.rb ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] Warming up -------------------------------------- Oj.load compat 34.274k i/100ms Calculating ------------------------------------- Oj.load compat 341.356k (± 3.6%) i/s (2.93 μs/i) - 3.427M in 10.056686s ```
- Loading branch information