Sort the conditional statements#946
Merged
ohler55 merged 1 commit intoohler55:developfrom Dec 28, 2024
Merged
Conversation
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 ```
ohler55
approved these changes
Dec 28, 2024
Owner
|
Thank you. Looks perfect. |
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.
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.Environment
Code
Before
After