HerokuRichard SchneemanBenchmark
We Patched Ruby On Rails for a 10% Performance Bump
Summary
Rails response time improved by more than 10% in a patch that also reduced allocated objects by 29%, motivated by memory and performance problems observed in production Heroku applications. The work began with customer reports of R14 out-of-memory errors, swap usage, and suspected memory leaks, then used a customer app and reusable benchmarks to reproduce issues. The derailed benchmarks perf:objects task and memory_profiler exposed allocation hot spots, including arrays joined into strings and duplicated hashes; refactoring reduced unnecessary objects, while routing changes produced a 31% speed increase for constrained URL generation. The resulting savings required no application changes and were planned for the next Rails version, with Rails 5 pre-release testing mentioned.
Context
Heroku applications were experiencing R14 out-of-memory errors, rapid swap usage, slow performance, and concerns about memory leaks. Customer reports and dashboard metrics exposed these problems, prompting investigation into Rails and application memory use.
Approach / What changed
Reusable benchmarks reproduced customer issues, while derailed benchmarks and memory_profiler identified Rails allocation hot spots. The patch refactored code to avoid temporary arrays and duplicated hashes, modify objects in place where appropriate, and use pooled frozen strings; routing code was also optimized.
Takeaways
The patch improved Rails response time by more than 10% and reduced allocated objects by 29%.
A constrained URL-generation route using GitHub-style routes became 31% faster after routing optimizations.
Applications can receive the improvements by upgrading Rails without changing how their Rails apps are written.
Source and freshness
- Source
- heroku.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.