Benchmarking methodology

wrk is a modern HTTP benchmarking tool capable of generating significant
load when run on a single multi-core CPU.

wrk -t10 -c10 -d10s http://localhost:3000

This runs a benchmark for 10 seconds, using 10 threads, and keeping 50 HTTP connections open i.e. this should suffice. Just remember to benchmark on your actual app to see the real improvements.

The escape_utils gem

Just faster all html escaping via the lovely escape_utils gem. In order to use it in Rails one needs to add an initializer that patches things up:

beginrequire'escape_utils/html/rack'# to patch Rack::Utilsrequire'escape_utils/html/erb'# to patch ERB::Utilrequire'escape_utils/html/cgi'# to patch CGIrequire'escape_utils/html/haml'# to patch Haml::HelpersrescueLoadErrorRails.logger.info'Escape_utils is not in the gemfile'end

The fast_blank gem

Living under the impression that the blank? method is too slow? say no more and just try the fast_blank gem!

Just add gem 'fast_blank' to your Gemfile and this should speed up quite nicely the String#blank? method as described in this article . For testing I just added this code:

fast_blank is a simple extension which provides a fast implementation of active support's string#blank? function

deffast_blank_testn=1000strings=["","\r\n\r\n ","this is a test"," this is a longer test"," this is a longer test
this is a longer test
this is a longer test
this is a longer test
this is a longer test"]Benchmark.bmbmdo|x|strings.eachdo|s|x.report("Fast Blank #{s.length} :")don.times{s.blank?}endendendrendernothing: trueend

Dig into your Rails app

Conclusion

Depending on what your app is doing you might want to add to your Gemfile some of these gems, I usually add them all just for good measure (you might want to check your RAM usage and have a full test suite before doing this though).

The oj gem is just great for a Rails based JSON API where you can drop the views and just serialize using representers or your pattern of choice.