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

Methods defined with `define_method` are slower to call

Open
#22 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
42/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby

Research direction

Start by locating the existing comparison of define_method and module_eval in the repository, then review the benchmark shown in the issue. Done means documenting that calling methods created with define_method is slower, alongside the existing method-definition comparison and its performance tradeoff.

Written by the indexing model from the issue text.

Description

Suggestion

While define_method indeed defines methods slighly faster than module_eval, I think it should be noted that calling methods defined with define_method is slower than calling module_eval ones (because define_method creates a closure):

require "benchmark/ips"

object = Class.new {
  module_eval "def evaled_method; end"
  define_method(:defined_method) {}
}.new

Benchmark.ips do |x|
  x.report("module_eval")   { object.evaled_method }
  x.report("define_method") { object.defined_method }
  x.compare!
end
Calculating -------------------------------------
         module_eval    98.664k i/100ms
       define_method    93.809k i/100ms
-------------------------------------------------
         module_eval      6.794M (± 8.1%) i/s -     33.743M
       define_method      4.588M (± 6.7%) i/s -     22.889M

Comparison:
         module_eval:  6793763.3 i/s
       define_method:  4587570.1 i/s - 1.48x slower

I think you benefit more from a method being faster to call than faster to define.

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.