Profile your gem memory usage with Derailed

Is your Rails app is taking up a lot of RAM? Perhaps your application’s memory footprint is being enlarged by one or more bloated gems. The Derailed gem provides some awesome tools for detecting gem bloat.

So your Rails app is taking up a lot of RAM. What else is new? But perhaps this isn't just the way things are. Perhaps your application's memory footprint is being enlarged by one or more bloated gems.

I recently stumbled across a very cool project by Richard Schneeman. It's called derailed, and is a collection of automatic benchmarking tools. Here's the github repo.

All you need to do is add it to your gemfile like so:

gem 'derailed', group: :development
gem "stackprof", group: :development

Then you can see exactly how much memory each of your gems requires at compile time:

Use the bundle:mem command to see how much ram each of your gems uses at compile time Use the bundle:mem command to see how much ram each of your gems uses at compile time

You can also see how many objects are allocated by your gems at load time.

Use the bundle:objects to see information about object allocation at load time Use the bundle:objects to see information about object allocation at load time

There are even tools for measuring memory usage as your application runs. I haven't had a chance to check these out personally yet, since you have to be able to run your app in production mode on your development computer.

What to do next:
  1. Try Honeybadger for FREE
    Honeybadger helps you find and fix errors before your users can even report them. Get set up in minutes and check monitoring off your to-do list.
    Start free trial
    Easy 5-minute setup — No credit card required
  2. Get the Honeybadger newsletter
    Each month we share news, best practices, and stories from the DevOps & monitoring community—exclusively for developers like you.
    author photo

    Starr Horne

    Starr Horne is a Rubyist and Chief JavaScripter at Honeybadger.io. When she's not neck-deep in other people's bugs, she enjoys making furniture with traditional hand-tools, reading history and brewing beer in her garage in Seattle.

    More articles by Starr Horne