Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Speeding up Rails 4.2 (samsaffron.com)
197 points by mdasen on Dec 1, 2014 | hide | past | favorite | 16 comments


This is really great – but I guess I'm a little concerned that large performance regressions aren't being caught at an earlier stage. I wonder if there's scope to automatically keep tabs on Rails Edge performance?


It would be great if there was a performance benchmark run on CI stack or something and writing output in parseable format so it could be graphed over time etc.


Sam has also blogged about this for Ruby specifically: http://samsaffron.com/archive/2013/12/11/call-to-action-long...


This is exceedingly great work. This is the stuff I love coming to HN for. I had no idea Discourse had a dual-boot mode, much less that it had become a de-facto macro benchmark for both Ruby and Rails. That is awesome.


You guys might like our latest gem, it outputs ruby-prof as FlameGraphs https://github.com/oozou/ruby-prof-flamegraph


Awesome, I love flamegraphs for finding performance bottlenecks.


Sam is a smart guy and an awesome developer. He contributed tons of code for .NET community when he worked at Stack Overflow.

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.


String interning has nothing to do with static typing. AFAIK Ruby supports it with symbols and Python with strings in general.


Recent rubys also supports it for frozen strings (which is the reason it's a frozen string in the commit, probably).

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.


Ruby 2.2 will add almost-automatic-freezing of string hash keys[1]. I wonder how big of an impact this will have on Rails performance.

[1] http://www.sitepoint.com/unraveling-string-key-performance-r...


Great write-up, and thanks Sam and Sean!

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! ..


Makes me wonder if Adequate Record has much impact at all on typical app patterns. Has AdRec been obliterated by other stuff, or is it a microbenchmark that just didn't effect the OP's app much?


Sam Saffron has great write-ups. His article on Ruby 2.1 and garbage collection fine-tuning [1] is a must-read

[1] http://samsaffron.com/archive/2014/04/08/ruby-2-1-garbage-co...


Thanks, this is both enormously helpful work for those in the Rails community who depend on the new hotness, and a great writeup for increasing engineering skill levels throughout the community.


Amazing work! I've bookmarked this post. I think that this approach of profiling Discourse on Rails could be use for any other app/service that is to be migrated to Rails 4.2.


You are the man! Thanks for the great insight on the performance.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: