0Pricing
Ruby Academy · Lesson

Common Bottlenecks

Speed up Ruby code.

Recognizing Bottlenecks

Most Ruby slowdowns come from a few recurring patterns. Knowing them lets you fix code quickly.

  • Wrong data structure for the job
  • Repeated work that could be cached
  • N+1 queries and nested loops

This lesson covers the most common offenders.

puts 'Speeding up Ruby starts with knowing the usual suspects'

Array#include? vs Set

Checking membership with Array#include? is O(n). A Set (or hash) gives O(1) lookups.

  • For repeated membership checks, build a Set once
  • Huge speedup on large collections
require 'set'

allowed = Set.new(['a', 'b', 'c'])
puts allowed.include?('b')
puts allowed.include?('z')

All lessons in this course

  1. Measuring Performance
  2. Profiling Tools
  3. Memory Optimization
  4. Common Bottlenecks
← Back to Ruby Academy