explaingit

fastruby/fast-ruby

5,730RubyAudience · developerComplexity · 1/5Setup · easy

TLDR

Fast Ruby is a living reference of Ruby coding patterns paired with benchmarks showing which version of each idiom runs faster, helping developers make small, targeted speed improvements to their Ruby code.

Mindmap

mindmap
  root((repo))
    What it does
      Idiom comparisons
      Benchmarks per pattern
      Auto-updated via CI
    Categories
      Arrays and hashes
      Strings and dates
      Iterators and ranges
      General language
    Companion tool
      Fasterer scanner
      Flags slow idioms
    Usage
      Reference guide
      Run locally
      Contribute new patterns
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Look up the faster of two equivalent Ruby idioms before writing performance-sensitive code

USE CASE 2

Run the fasterer companion tool on your own Ruby codebase to flag slow patterns automatically

USE CASE 3

Study the benchmark source files to learn how to write accurate microbenchmarks in Ruby

USE CASE 4

Contribute a new idiom comparison by adding a benchmark file and updating the README

Tech stack

Ruby

Getting it running

Difficulty · easy Time to first run · 5min
No license information is specified in the repository.

In plain English

Fast Ruby is a reference collection of Ruby coding patterns, each paired with a benchmark showing which version of the code runs faster. The project grew out of a 2014 conference talk about writing performant Ruby and has since been maintained as a living document that Ruby developers can consult when they want to make small, targeted speed improvements. The collection covers many categories of common Ruby operations: general language features, arrays, hashes, strings, dates, ranges, iterators, and more. For each pairing, the README shows two or more ways to accomplish the same thing in Ruby, runs them against a benchmarking tool, and reports how many times per second each version can execute. A typical entry might compare two methods of checking whether an object responds to a particular method, with one approach running several times faster than the other. The project is careful to note that these are not universal rules to apply without thinking. Some alternatives only apply in certain situations, and swapping one idiom for another without understanding the context can introduce bugs. The README treats each entry as guidance rather than a strict prescription. Benchmarks are run automatically via a continuous integration workflow on GitHub so that results stay current as the Ruby language evolves. The numbers shown in the README reflect a specific Ruby version and machine configuration, and results on other systems will differ. A companion static analysis tool called fasterer can scan your own codebase and flag places where the faster idioms from this collection could apply. The repository also contains the source code files for every benchmark, so anyone can run the comparisons locally or adapt them for their own testing. Contributions adding new idiom comparisons are welcome. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Show me the top 5 fastest Ruby array patterns from the fast-ruby collection and rewrite this slow array processing method in my code to use them.
Prompt 2
I want to add a new benchmark to fast-ruby comparing two ways to check if a Hash key exists. Help me write the benchmark script and the README entry in the project's format.
Prompt 3
Run the fasterer gem against my Ruby on Rails app and for each flagged pattern, explain why the alternative in fast-ruby is faster and help me apply the fix.
Prompt 4
Help me understand why String#freeze is listed as a faster pattern in fast-ruby, explain the Ruby object model reason and show me where to apply it in this code.
Open on GitHub → Explain another repo

← fastruby on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.