Since the invocation to get the file and line number is so long, I added a helper method sup. Make sure tracing is started early as possible, I usually put this code in the top of my Gemfile. Remove this code when you’re not debugging, tracing allocations has a performance impact.

There are some caveats: In this example the hash is frozen, but the keys and values are not. If you try to modify a key or value, no exception will be raised. If you’re trying to freeze a complex object such as a Hash, you’ll need to deep freeze it. This technique also won’t work for cases where a variable is assigned instead of mutated.

Un-debug a gem

If you’ve opened a gem and added debug statements, but forget to remove them before closing the file: you’ll get those debug statements every time you run your program. To reset every gem to its original state you can use gem pristine. For example to reset Active Support:

Note: this may take a LONG time, especially if you’ve got gems with c-extensions.

Missing Pieces Wish List

Warning: These things don’t exist, but I wish they did. Don’t try to use them, they won’t work.

Here’s a list of things I want to do from time to time, but haven’t found a way to yet. Some of these might not be possible due to limitations in the VM. When a “missing piece” is found it is removed from this section and given it’s own heading above.

Find where a variable is over-written with a different value. While we can use the freeze trick to see where a value is modified, we won’t see when it is replaced.

config.thing={"foo"=>"bar"}.freezeconfig.thing=nil# No error is raised as the hash isn't being mutated, the variable is being assigned a different value

Not debugging

These are a few tricks that aren’t debugging related, but I’ve found helpful for understanding how the interpreter works.

Subscribe to my Newsletter 😻 🤠

Keep Reading 🚀

Today I have an unusual proposition for you. I’m spending a bunch of time to try to get Beto elected to Texas Senate, so I’ve not been able to write as much technical content. Rather than slow down on my door knocking, I’m looking to pick up the pace, and I want you to do it with me. Starting today, I’m offering anyone who phone banks or “block walks” (knocks on doors) the opportunity to win some of my technical time. Here’s how it’s going to work.

You might know rubocop as the linter that helps enforce your code styles, but did you know you can use it to make your code faster? In this post, we’ll look at static performance analysis and then at the end there’s a video of me live coding a PR that introduces a new performance cop to rubocop.

Rails 5.2 was just released last month with a major new feature: Active Storage. Active Storage provides file uploads and attachments for Active Record models with a variety of backing services (like AWS S3). While libraries like Paperclip exist to do similar work, this is the first time that such a feature has been shipped with Rails. At Heroku, we consider cloud storage a best practice, so we’ve ensured that it works on our platform. In this post, we’ll share how we prepared for the release of Rails 5.2, and how you can deploy an app today using the new Active Storage functionality.