Rails Performance Gems and Tricks
28 Nov 2017
Reading time:
1 min
A small collection of gems and tricks I use for measuring and enhancing a Rails app performance. I’ll keep this post updated with new gems and tricks :)
Gems
- (Benchmark) rack-mini-profiler. Profiler for your development and production Ruby rack apps
- (Benchmark) ruby-prof. A code profiler for MRI rubies (Thanks Ana María!)
- (Benchmark) derailed_benchmarks. Benchmarks for your whole Rails app
- (Cache) bootsnap. Boot large Ruby/Rails apps faster
- (Database/Queries) bullet. Easy detecting N+1 queries
- (Database/Queries) ankane/dexter. The automatic indexer for Postgres
- (Heroku only) heroku-deflater. Add the gem on the production group and enjoy gziped served assets
Tips
- Use
Rack::Deflater
(Original post. Thanks Schneeman!)
This tip is incredible! It just uses a Rack stdlib to compress your HTML.
Add the config.middleware.insert_after ActionDispatch::Static, Rack::Deflater
line on your config/application.rb
, and voilà!
- Set a reasonable
MALLOC_ARENA_MAX
if you have memory bloat (Original post. Thanks Nate!)
Ruby memory allocation can be tricky, as this post is a very deep analysis on what’s going on behind the curtains.