During my quest for faster RSpec tests I've come across several interesting posts about Ruby. Being new to the language they've helped me understand a bit more about the internals. Posting them here so they don't get lost.
The road to faster tests - a story about tests and garbage collection.
Tuning Ruby garbage collection for RSpec - practical explanation of Ruby's garbage collector and how to adjust its performance for RSpec
Probably the very first posts I found referencing slow RSpec tests. It turned out
this was not the issue but I've nevertheless tried running GC manually. I can clearly
puts GC.count in after()) GC invoked less frequently, memory usage rising
but the overall execution time wasn't affected. The profiler said 2% speed increase
to be honest.
Not being very clear about the different profiling tools available and how to interpret their results I've found these articles:
Profiling Ruby With Google's Perftools - practical example for using perftools.rb
Show runtime for each rspec example
Suggestions for Faster Tests
Several general best practices for faster tests:
I've noticed Bundler loading tons of requirements (nearly 3000 unique modules) and for some particular specs this wasn't necessary (for example running Rubocop). I've found the following articles below which sound very reasonable to me:
Finally (or more precisely first of all) I've seen this Weird performance issue.
During my initial profiling I've seen (and still see) a similar issue. When calling require it goes through lots of hoops before finally loading the module. My profiling results show this taking a lot of time but this time is likely measured with profiling enabled and doesn't represent the real deal.
On my MacBook Air with Red Hat Enterprise Linux 7 this happens when using Ruby 2.2.2 from Software Collections. If using Ruby installed from source with rbenv the profiling profile is completely different.
I will be examining this one in more details. I'm interested to know what is the difference and if that affects performance somehow so stay tuned!