Adopt five open benchmark PRs - #244
Merged
Merged
Conversation
From #174 by @kewlar: picking values by keys, when some keys may be missing and their default values matter. values_at is the fast one. Lands the file as the PR wrote it, without the spaces padding one report label, on today's main. The README entry keeps the PR's sample (Ruby 3.2, 1.75x) and adds one from ruby_4.0 (2.05x). Local runs agree on ruby_2.1, 3.4, 4.0, head and jruby_head (1.52x to 2.10x); truffleruby_head had map 1.06x ahead in one run. Co-authored-by: Mindaugas Pelionis <1241866+kewlar@users.noreply.github.com>
From #182 by @yogeshjain999: when to define a method, forward it with def_delegator, or let SimpleDelegator handle it. The plain method is the fast one. Two changes to the PR's file: - The delegated report called pop(1) while the others push, so it measured different work. It now calls << 1, which SimpleDelegator passes to the array, and all three return [1]. - slowest becomes slower, so the rank names do not skip a step. The README entry keeps the PR's sample (Ruby 2.2, measured the pop version) and adds one from ruby_4.0 on the current code: forwarded 1.24x, delegated 2.55x slower. Local runs keep that order on ruby_2.1, 3.4, head and jruby_head; on truffleruby_head all three tie, the work optimized away. Co-authored-by: Yogesh Khater <6301525+yogeshjain999@users.noreply.github.com>
From #140 by @jrmhaig: how the Array#sum added in Ruby 2.4 compares with the usual inject(:+). sum is the fast one. Changes to the PR's file: - Wrapped in if RUBY_VERSION >= '2.4.0', as suggested on the PR, so it skips Rubies without Array#sum instead of crashing (checked on ruby_2.1, 2.3 and jruby_9.1; runs on 2.4 and truffleruby_22). - Drops require "rubygems", which no Ruby in CI needs. - Labels Array#sum and Array#inject(:+). - A comment that the two only agree for Integers: for Floats, sum compensates for rounding errors. The PR's .travis.yml change is left out: main no longer has Travis. The PR had no README entry; the new one, next to the inject entry, is from ruby_4.0 (sum 1.56x faster). Co-authored-by: Joseph Haig <4415912+jrmhaig@users.noreply.github.com>
From #237 by @etagwerker, which revisits #125 by @gabteles and fixes its reversed Set#subset? arguments: five ways to check that every element of one array is in another. (a1 - a2).empty? is the fast one, as the PR found on Ruby 3.3, 3.4 and 4.0. Changes to the PR's file: - Rank-named methods instead of minus_empty, all_include and so on: faster (a1 - a2).empty?, fast all? + include?, then slow, slower and slowest for (a1 & a2).size, (a1 & a2) == a1 and Set#subset?. - A comment on where the winner changes: all? + include? wins on JRuby and TruffleRuby, and ties on Ruby 2.1. - The PR's header comment on one line per sentence. The README entry keeps the PR's text and its 3.3, 3.4 and 4.0 runs, and adds one from ruby_4.0.7. Co-authored-by: Ernesto Tagwerker <17584+etagwerker@users.noreply.github.com> Co-authored-by: Gabriel Teles <3189895+gabteles@users.noreply.github.com>
…124) From #236 by @etagwerker, which revisits #124 by @sFrenkie and fixes its data (it had no nil values, so compact did less work): three ways to collect the non-nil values of a hash. values.compact is the fast one. Changes to the PR's file: - The data no longer uses Random.rand, so the number of nils does not change from run to run: every other value is nil (500 of 1000). - The two select reports keep values with !v.nil? instead of by truthiness, so like compact they drop only nil and keep false (from the PR's Copilot review). The two snippets in the README text change the same way. - Rank-named methods: fast values.compact, slow values.select, slower select.values, the order on every CRuby and JRuby run. - The sanity check compares the results as they are, without sorting, since all three keep the hash's order (from the PR's Copilot review). - Single quotes, as RuboCop asks. The README entry keeps the PR's ruby_4.0.0 sample, which ran the truthiness version, and adds one from ruby_4.0.7 on the current code (21.05x). Co-authored-by: Ernesto Tagwerker <17584+etagwerker@users.noreply.github.com> Co-authored-by: sFrenkie <20856072+sFrenkie@users.noreply.github.com>
JuanVqz
force-pushed
the
feature/adopt-open-prs
branch
from
September 29, 2026 00:33
2968729 to
994cecc
Compare
JuanVqz
marked this pull request as ready for review
September 29, 2026 00:33
This was referenced Sep 29, 2026
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.
Summary
Changes
Step 1:
Hash#values_atvsArray#map { Hash#[] }(#174 by @kewlar)values_atwins on Ruby 2.1, 3.4, 4.0, head and JRuby head (1.52x to 2.10x). On TruffleRuby headmapwas 1.06x ahead in one run, so no comment until CI confirms it.Step 2: method vs forwarded method vs delegated method (#182 by @yogeshjain999)
pop(1)while the other two push, so it measured different work. It now calls<< 1, whichSimpleDelegatorpasses to the array, and all three return[1].slowestbecomesslower, so the rank names do not skip a step.popversion.Step 3:
Array#sumvsArray#inject(:+)(#140 by @jrmhaig)if RUBY_VERSION >= '2.4.0', as suggested on the PR, so it skips Rubies withoutArray#suminstead of crashing.require "rubygems"and the.travis.ymlchange (mainno longer has Travis). LabelsArray#sumandArray#inject(:+).sumcompensates for rounding errors.Step 4: array subset check (#237 by @etagwerker, from #125 by @gabteles)
minus_empty,all_includeand so on.(a1 - a2).empty?is the winner, as the PR found on 3.3, 3.4 and 4.0.all?+include?wins on JRuby and TruffleRuby, and ties on Ruby 2.1.Step 5: non-nil hash values,
values.compactvsselect(#236 by @etagwerker, from #124 by @sFrenkie)Random.randin the data, so the number of nils is the same on every run: every other value is nil.selectreports keep values with!v.nil?instead of by truthiness, so likecompactthey drop onlyniland keepfalse(from the PR's Copilot review). With{ a: false, b: nil, c: 1 }all three now return[false, 1]; the oldselect { |v| v }returned[1]. The README text's two snippets change the same way.values.compactis now 21.05x faster (13.78x before!v.nil?, which is a little more work thanv). The PR's ruby_4.0.0 sample, which ran the truthiness version, is kept.Test plan
!v.nil?changes; after them, it ran on 4.0.7.After this merges, each contributor PR gets a comment saying where it landed, and is closed.