Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`dup`ing an Identity Hash/Set is faster than creating a new one

Open
#230 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
52/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
ruby
Domain
performance

Research direction

Start by locating the repository's existing benchmark or idiom entry format, since no target file is named. Use the supplied Benchmark.ips examples for identity Hash and Set, and consider the work complete when the repository records the comparison and its allocation or performance result consistently with its other entries.

Written by the indexing model from the issue text.

Description

It's one less allocation, too :)

YJIT off YJIT on
Set.new.compare_by_identity 2.571M 4.260M
S.dup 3.014M 4.999M
1.17x 1.17x
YJIT off YJIT on
Hash.new.compare_by_identity 5.643M 8.208M
H.dup 5.988M 9.014M
1.06x 1.09x
S = Set.new.compare_by_identity.freeze
H = Hash.new.compare_by_identity.freeze

Benchmark.ips do |x|
  x.config(time: 10)

  x.report(".new.compare_by_identity") do |times|
    i = 0
    while (i += 1) <= times
      S.dup
    end
  end
  
  x.report(".dup                    ") do |times|
    i = 0
    while (i += 1) <= times
      Set.new.compare_by_identity
    end
  end
  
  x.compare!
end

Benchmark.ips do |x|
  x.config(time: 10)
  
  x.report(".new.compare_by_identity") do |times|
    i = 0
    while (i += 1) <= times
      H.dup
    end
  end
  
  x.report(".dup                    ") do |times|
    i = 0
    while (i += 1) <= times
      Hash.new.compare_by_identity
    end
  end
  
  x.compare!
end
Dominant language
Ruby
Stars
5.7k
Forks
370
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fastruby/fast-ruby

All issues in fastruby/fast-ruby

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.