Speeding up Rails 4.2
samsaffron.com
samsaffron.com
I have done a fair amount of performance optimization work in .NET/C#, so I was curious as to what kind of optimizations are involved in Ruby.
One of the optimization was this:
https://github.com/SamSaffron/rails/commit/9aa2b2d7bf52c0f39...
Three lessons:
1. Always use profiler to identify code bottlenecks. I don't think I would have ever guessed that the string literal is costing memory allocations causing performance issues.
2. I find it sad that this kind of optimization is required in 2015. In any statically typed language, this would be completely unnecessary.
3. Performance optimization makes code less readable. I think it would make sense to add comment explaining why constant ID was declared.
Here's another:
https://github.com/SamSaffron/rails/commit/a668b09ee387bf241...
Same story.
The reason it's not done by default is that with mutable strings it would be more complicates/would require a different string implementation, I guess.
[1] http://www.sitepoint.com/unraveling-string-key-performance-r...
Makes me wonder how bad it would have been without Adequate Record? I would imagine it's a bit disheartening for Aaron that all his hard work making AR 2-times faster have been obliterated by other stuff! ..
[1] http://samsaffron.com/archive/2014/04/08/ruby-2-1-garbage-co...