Wednesday, August 20, 2025

The Digital Press

All the Bits Fit to Print

Ruby Web Development Artificial Intelligence Urban Planning
Astronomy

Ruby Templating Boost: P2 Matches ERB Speed with New Compiler

Optimizing P2 gem to match ERB's compiled template performance

From Hacker News Original Article Hacker News Discussion

A Ruby developer created P2, a new HTML templating library that compiles Ruby code into efficient Ruby code to generate HTML, and optimized it to match the speed of compiled ERB templates.

Why it matters: P2’s compilation technique boosts Ruby template performance, showing Ruby can achieve speeds comparable to established tools like ERB.

The big picture: Despite Ruby’s reputation as a slower language, careful code generation and optimization can produce highly efficient Ruby programs.

Stunning stat: P2 improved from 669k to 1.45 million iterations per second, nearly matching ERB’s 1.57 million i/s on benchmarks.

Commenters say: Some view the headline as misleading, arguing Ruby remains slower than languages like Rust, and speed isn’t Ruby’s primary focus.