# Why Ruby on Rails Is a Great Fit for the AI Era: Performance, Tokens, and Architecture

Date: JUL 29, 2026
Description: Why Ruby 3 + YJIT is 2x faster than Python, how Ruby's concise syntax saves LLM tokens, and why Convention over Configuration is a natural fit for AI agents.

*This is the third part of the series about Ruby's future, inspired by Irina Nazarova's keynote ["Startups on Rails"](https://sfruby.com/rubyconfth) at RubyConf Thailand 2026. Earlier we discussed [myths and fears among engineers](/blog/ruby-in-2026-why-engineers-fear-ai) (Part 1) and [real AI startups](/blog/ai-startups-on-ruby-on-rails-4-real-cases) (Part 2). Today we move to technical facts and benchmarks.*

The old myth that "Ruby is slow" dates back over a decade. Let's see where things stand in 2026, with **Ruby 3**, the **YJIT** compiler, and LLM-based code generation.

---

### Fact 1: Ruby Is ~2.5x Faster Than Python

Ruby 3 introduced massive speedups over Ruby 2 (better memory management, GC, M:N threads), and YJIT by Shopify adds another 15-20% performance boost with a single flag.

Latest benchmark results from [bddicken/languages](https://benjdd.com/languages/) (run on an M3 MacBook Pro with 16GB RAM):

* **1 Billion Nested Loops:** Ruby (3.3.5) **28.80s** vs Python (3.9.6) **74.42s** — **Ruby is 2.58x faster**
* **Naïve Fibonacci (N=40):** Ruby (3.3.5) **12.17s** vs Python (3.9.6) **29.00s** — **Ruby is 2.38x faster**

Across general computation, standard **Ruby runs ~2.4x–2.6x faster than standard CPython**.

Comparing micro-frameworks ([TechEmpower Round 23](https://www.techempower.com/benchmarks/#hw=ph&test=fortune&section=data-r23), Fortunes test):

```
       Micro-Frameworks (Requests per second)

  Express.js (Node.js)  │ ██████████████████████████ 172.5K req/s
  Roda (Ruby + Iodine)  │ █████████████████████████  165.7K req/s
  FastAPI (Python)      │ ████████████████           109.1K req/s
  FastAPI + ORM (Python)│ █████                      37.8K req/s

```

Roda on Ruby runs at **96% of Express.js speed** (165.7K vs 172.5K req/s) and easily leaves Python's FastAPI far behind.

Full-stack frameworks (same source):

```
       Full-Stack Frameworks (Requests per second)

  Laravel Workerman     │ ██████████████████████████  49.5K req/s
  Rails Iodine          │ ████████████████████████    47.9K req/s
  Rails Puma (default)  │ ██████████████████████      42.5K req/s
  Rails Falcon          │ █████████████████████       40.6K req/s
  Django (Python)       │ ████████████████            32.6K req/s
  Laravel FPM (default) │ ████████                    16.4K req/s

```

Even default Rails (Puma at 42.5K req/s) beats optimized Django (32.6K req/s). And standard Rails outperforms default PHP/Laravel FPM (16.4K req/s) by **2.6x**.

---

### Fact 2: Token Savings in Code Generation (Token Efficiency)

In the era of AI agents (Cursor, GitHub Copilot, Claude Code), a language's conciseness directly affects context window usage, cost, and agent speed.

LLMs process code via **tokens**. The more tokens required to express logic, the faster you exhaust the context window and the higher the risk of model drift.

According to [Martin Alderson's study on language token efficiency](https://martinalderson.com/posts/which-programming-languages-are-most-token-efficient/) (using the GPT-4 tokenizer across RosettaCode tasks):

* **Ruby averages 116 tokens per task** — ranking #3 overall among major programming languages (beating Python, JavaScript, Java, Go, Rust, and C#).
* **Python:** 128 tokens (~10% more tokens than Ruby).
* **JavaScript:** 181 tokens (~56% more tokens than Ruby).
* **Java (187 tokens), Rust (198 tokens), Go (207 tokens), C# (211 tokens):** Require **60% to 80% more tokens** than Ruby for the exact same task.
* **C++ (264 tokens) & C (285 tokens):** Require over **2.4x more tokens** than Ruby.

```
┌─────────────────────────────────────────────────────────────┐
│  Average Tokens per Task (GPT-4 Tokenizer, Lower = Better)  │
├─────────────────────────────────────────────────────────────┤
│ Ruby        █████████ 116 tokens                            │
│ Python      ██████████ 128 tokens                           │
│ JavaScript  ██████████████ 181 tokens                       │
│ Java        ███████████████ 187 tokens                      │
│ Rust        ████████████████ 198 tokens                     │
│ Go          █████████████████ 207 tokens                    │
│ C#          █████████████████ 211 tokens                    │
└─────────────────────────────────────────────────────────────┘

```

Alderson followed this up by analyzing web frameworks, demonstrating that **framework choice matters even more than language choice** for AI agents. In Rails, standard conventions remove boilerplate, keeping prompt context clean and focused on business logic.

---

### Fact 3: Convention over Configuration Is a Natural Fit for AI Agents

How do AI agents work when writing code for other stacks? You end up creating massive `AGENTS.md` or `CLAUDE.md` files, explaining to the model where controllers live, how to name routes, and how to structure the database. There are now over 60,000 repos with `AGENTS.md` files telling AI about project structure.

In Rails, the principle of **Convention over Configuration** means:

1. AI models *already know* Rails conventions because they were trained on 20 years of open source repositories following the same patterns.
2. The architecture is predictable: the model knows exactly that `User` lives in `app/models/user.rb`.
3. No `CLAUDE.md` needed to explain where models, controllers, and tests go. The framework is the prompt. The agent focuses only on **business logic**.

---

### Architectural Pragmatism: Dropping the Purism

Irina Nazarova stresses: to build fast systems in 2026, the community needs to let go of purism.

```
  ┌──────────────────────────────────────────────────────────┐
  │              Modern Rails Application Stack              │
  ├───────────────────────┬──────────────────────────────────┤
  │ Business logic        │ Ruby on Rails (maximum velocity) │
  ├───────────────────────┼──────────────────────────────────┤
  │ Heavy Async / Sockets │ AnyCable / Go / Rust             │
  ├───────────────────────┼──────────────────────────────────┤
  │ ML models             │ Python (via API / gRPC)          │
  ├───────────────────────┼──────────────────────────────────┤
  │ Frontend              │ React, Vue, Svelte via Inertia   │
  └───────────────────────┴──────────────────────────────────┘

```

Databases are written in C++, heavy build tools in Go/Rust, and ML model logic runs on Python. The infrastructure tools should know nothing about your business logic — they just provide performance. Rails stays the brain of the application, where the business logic lives, easy for both humans and AI to read and write.

➡️ **[Read Part 4: What Ruby Is Missing for AI and How the Community Can Take Back the Initiative](/blog/what-ruby-is-missing-for-ai-and-how-to-take-back-initiative)**
