Skip to content

Fix Rails 8.1+ compatibility replacing Benchmark with Process.clock_gettime#43

Closed
joshRpowell wants to merge 1 commit intomakandra:masterfrom
joshRpowell:fix-benchmark
Closed

Fix Rails 8.1+ compatibility replacing Benchmark with Process.clock_gettime#43
joshRpowell wants to merge 1 commit intomakandra:masterfrom
joshRpowell:fix-benchmark

Conversation

@joshRpowell
Copy link
Copy Markdown

@joshRpowell joshRpowell commented Oct 27, 2025

In Ruby 3.4+, the Benchmark constant is no longer reliably available
in gem contexts when loaded through Rails 8.1, causing NameError: uninitialized constant Benchmark.

This replaces Benchmark.realtime with Process.clock_gettime, which:

  • Is part of Ruby core and doesn't require loading (since ruby 2.x)
  • Provides the same monotonic time measurement
  • Returns elapsed time in seconds as a Float (identical to Benchmark.realtime)
  • Maintains backward compatibility with all existing functionality

Fixes compatibility with:

  • Ruby 3.4+
  • Rails 8.1+

No behavior changes - Process.clock_gettime(Process::CLOCK_MONOTONIC)
is actually what Benchmark.realtime uses internally.

@FLeinzi
Copy link
Copy Markdown
Contributor

FLeinzi commented Oct 27, 2025

Hi @joshRpowell,

thanks for figuring out. I extracted your change to a module QueryDiet::Benchmark (easier to test 😉) and added Ruby 3.4.4 and Rails 8.1 to our spec matrix. I will release a new version of the gem soon.

#44

@FLeinzi
Copy link
Copy Markdown
Contributor

FLeinzi commented Oct 27, 2025

Version 0.7.3 is released now.

@FLeinzi FLeinzi closed this Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants