So, creating a situation where you're guaranteeing an exception is raised during non-exceptional execution flow is generally a bad idea. It may be cleaner or more concise code-wise, but performance-wise it almost certainly will always be slower.
For the most part I believe the parent is correct in that there is a much stronger emphasis placed on code conciseness/clarity than there is on avoiding performance anti-patterns. It's hard to measure whether the gains in "code agility" outweigh the local performance hit by making it easier to surface other performance problems. When there's less code involved it usually follows that it's easier to spot and fix problems. But I worry because my own experience suggests that death of a thousand cuts is a considerably harder situation to get out of than dealing with a handful of gnarlier bottlenecks.
Except that exception handling is so fast in 1.9.2 that it made this change a performance optimization in 1.9.2. Look lower in this topic for benchmarks showing that Rails 3 is faster in 1.9.2 than rails2 is under 1.8.7.
>performance-wise it almost certainly will always be slower
Except, it wasn't slower in the Ruby that most people running Rails 3 should be running (1.9.2).
I also point out, again, that they immediately fixed this problem when someone pointed out how slow it was in 1.8.7.
Now, I could be completely off-base and 1.9.2 may be the only system out there that has managed to make exception handling a cheap operation. But I'm highly skeptical of that. I think the more likely scenario is exception handling is much cheaper in 1.9.2 than 1.8.7, but still not cheap enough to favor over virtually anything else. I've not read anywhere in the linked issue or in the following comments that suggests using responds_to? was any slower than handling a NoMethodError exception. If it is, that largely points at a failure of responds_to? more than it trumpets the speed of ruby exception handling. And pretending that exception handling is fast enough for flow control and thus other problems needn't be fixed can land a community in serious trouble.
Now obviously there are exceptions to every rule. But the default position of any programmer really should be to reserve exceptions for exceptional circumstances because they are almost axiomatically slow, regardless of language or platform.
http://stackoverflow.com/questions/4789248/rails-3-initializ...
http://stackoverflow.com/questions/5516428/slow-deployment-f...
In Ruby 1.9.2 (p180 and -head), the application starts 26 seconds. In REE 1.8.7, it takes 8 seconds.
With 1.8.7 REE's garbage collection settings tuned, the page renders in two seconds.
With 1.9.2, the page renders in four seconds.
http://dl.dropbox.com/u/6607107/dev.tanga.gif
46% of the time is spent garbage collecting.
Its easy enough to spout platitudes like "don't use exceptions for flow control", except remember two basic facts about the commit that I linked:
1. It was using exceptions for flow control as an optimization 2. That optimization was indeed faster on 1.9.2
On top of that, when the rails team was notified about how bad this "optimization" was in 1.8.7, they immediately fixed it.
I just don't see how any of this fits into "don't give a shit about performance".
I think it is very interesting that the specific test produced in the original post is actually faster under Rails 3 and Ruby 1.9.2 than it is under Rails 2 and 1.8.7.
My only grief with you, fauigerzigerk, is that you claim the Rails team doesn't "give a shit about performance", when the performance problems seem to be related to people using an older version of Ruby. I think you are making an extraordinary claim -- that the rails team doesn't "give a shit", in in fact, they clear do give a shit.
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/...
What was originally a performance optimization on 1.9.2 caused a terrible slowdown on 1.8.7. It was reported and fixed within two days.
Does that still fit into your "not giving a shit about performance" critique? I think the "real problem" is that there are two major releases of MRI Ruby (not to mention JRuby) that have very different performance characteristics.