<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/benchmarks-are-free-now-307ftwxma" -->

---
title: Benchmarks Are Free Now | daily.dev
description: A Ruby gem maintainer describes how a correctness fix to ruby-enum (handling inheritance of class-level instance variables) introduced a 5x performance...
canonical: https://daily.dev/posts/benchmarks-are-free-now-307ftwxma
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Benchmarks Are Free Now | daily.dev
og:description: A Ruby gem maintainer describes how a correctness fix to ruby-enum (handling inheritance of class-level instance variables) introduced a 5x performance...
og:url: https://daily.dev/posts/benchmarks-are-free-now-307ftwxma
og:image: https://api.daily.dev/og/posts/307FTWXmA.png
og:image:alt: Benchmarks Are Free Now
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Benchmarks Are Free Now

**[RUBYLAND](https://daily.dev/sources/rubyla)** · 4 min read · 0 upvotes · 0 comments

## Summary

A Ruby gem maintainer describes how a correctness fix to ruby-enum (handling inheritance of class-level instance variables) introduced a 5x performance regression in lookup methods because the fix recomputed a merged hash on every call with no caching. The test suite, which only checked correctness, missed it. Using Copilot CLI, the author quickly generated a benchmark script that immediately revealed the slowdown, then fixed it by memoizing the hash. A follow-up benchmark comparing Ruby::Enum operations to plain Ruby equivalents quantified the gem's overhead (constant access is free, hash lookups cost 3-5x, the Case matcher costs 50-100x), numbers now documented in the README's Performance section. The broader point: AI coding assistants have made writing throwaway benchmark scripts cheap enough that they're now worth doing for small changes.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://code.dblock.org/2026/08/15/benchmarks-are-free-now.html>

## Questions this post answers

### Why did adding inheritance support to a Ruby enum library make value lookups 5x slower?

The fix that made enum lookup methods walk up the superclass chain to merge parent enums recomputed the merged hash on every single call with no caching. A one-level subclass paid to rebuild a new hash while the superclass rebuilt its own too, so a call like .value became roughly 5x slower on a subclass and worse at deeper inheritance levels. Memoizing the merged hash and invalidating it only when define adds a new entry fixed it.

_Track down subtle regressions like this by following ruby gem maintenance stories on daily.dev._

### How much overhead does the ruby-enum gem add compared to plain Ruby hash and case statements?

Constant access such as Colors::RED is exactly as fast as a plain Ruby constant, so there is no cost there. Hash-backed lookups like .value and .key? carry a real 3-5x cost versus calling Hash#[] directly, due to extra method dispatch and object wrapping. The Ruby::Enum::Case exhaustive matcher is far more expensive, running 50-100x slower than a native case statement.

_Compare library overhead trade-offs like this before picking a dependency, tracked on daily.dev._

## Similar posts on daily.dev

- [Ruby Instance Variables Are Not Inherited \(and Why That Breaks Your DSL\)](https://daily.dev/posts/ruby-instance-variables-are-not-inherited-and-why-that-breaks-your-dsl--gbn1gpbrt) · RUBYLAND · 1 upvotes · 0 comments
- [Replacing a Rust Enum with a 64-bit Word Made My Interpreter 17% Faster](https://daily.dev/posts/replacing-a-rust-enum-with-a-64-bit-word-made-my-interpreter-17-faster-vl1pbon5a) · Pointers Gone Wild · 7 upvotes · 1 comments
- [When Your Hash Becomes a String: Hunting Ruby’s Million-to-One Memory Bug](https://daily.dev/posts/when-your-hash-becomes-a-string-hunting-ruby-s-million-to-one-memory-bug-nhlgsnql3) · Closer to Code · 0 upvotes · 0 comments
- [Issue \#812: RuboCop goes project-wide with Rubydex — Ruby Weekly](https://daily.dev/posts/issue-812-rubocop-goes-project-wide-with-rubydex-ruby-weekly-hpeftuyzb) · Ruby Weekly · 1 upvotes · 0 comments
- [Writing code got cheap. Being responsible for it didn't. \(What shipping an AI-generated gem taught me\)](https://daily.dev/posts/writing-code-got-cheap-being-responsible-for-it-didn-t-what-shipping-an-ai-generated-gem-taught-m-bvsq9cmas) · Ruby Flow · 0 upvotes · 0 comments

---

Tags: [#performance](https://daily.dev/tags/performance), [#ruby](https://daily.dev/tags/ruby)

[View this post on daily.dev](https://daily.dev/posts/benchmarks-are-free-now-307ftwxma)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Benchmarks Are Free Now","url":"https://daily.dev/posts/benchmarks-are-free-now-307ftwxma","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/benchmarks-are-free-now-307ftwxma"},"datePublished":"2026-08-15T02:51:02.404Z","dateModified":"2026-08-15T02:51:24.995Z","description":"A Ruby gem maintainer describes how a correctness fix to ruby-enum (handling inheritance of class-level instance variables) introduced a 5x performance...","image":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","thumbnailUrl":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","isAccessibleForFree":true,"articleSection":"RUBYLAND","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"RUBYLAND","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/rubyla","url":"https://daily.dev/sources/rubyla"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/benchmarks-are-free-now-307ftwxma","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"performance,ruby","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"RUBYLAND","item":"https://daily.dev/sources/rubyla"},{"@type":"ListItem","position":3,"name":"Benchmarks Are Free Now"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/benchmarks-are-free-now-307ftwxma#faq","mainEntity":[{"@type":"Question","name":"Why did adding inheritance support to a Ruby enum library make value lookups 5x slower?","acceptedAnswer":{"@type":"Answer","text":"The fix that made enum lookup methods walk up the superclass chain to merge parent enums recomputed the merged hash on every single call with no caching. A one-level subclass paid to rebuild a new hash while the superclass rebuilt its own too, so a call like .value became roughly 5x slower on a subclass and worse at deeper inheritance levels. Memoizing the merged hash and invalidating it only when define adds a new entry fixed it. Track down subtle regressions like this by following ruby gem maintenance stories on daily.dev."}},{"@type":"Question","name":"How much overhead does the ruby-enum gem add compared to plain Ruby hash and case statements?","acceptedAnswer":{"@type":"Answer","text":"Constant access such as Colors::RED is exactly as fast as a plain Ruby constant, so there is no cost there. Hash-backed lookups like .value and .key? carry a real 3-5x cost versus calling Hash#[] directly, due to extra method dispatch and object wrapping. The Ruby::Enum::Case exhaustive matcher is far more expensive, running 50-100x slower than a native case statement. Compare library overhead trade-offs like this before picking a dependency, tracked on daily.dev."}}]}
```

