Profiling JSON request in Rails using Rack Mini Profiler

6 April
  • rails, profiling, json

I often use the rack-mini-profiler gem while developing my Rails applications. It’s a ruby gem which provides information in-page about the speed of processing the request. It shows the number of queries and what parts of your code take the longest. I like running it in my dev environment as it helps me to quickly review the performance of each page.

I’ve needed to review the performance of API requests in the past but have struggled for a recent project it came up again. After a bit of searching, I found out that, if rack mini profiler can’t display the results, it will collect them until it can on the next HTML page. So, the solution that I am using is to:

  1. make the JSON request and
  2. then hit an HTML page of my choice.
  3. The results will appear, along with the most recent HTML profile.

It’s a little clunky but does the job. I hope it helps someone else.