Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

More optimizations on respond_to after a profile and benching:

App with simple respond_to:
  def index
    respond_to do |format|

On JRuby (after complete hotspot warmup) -- 8% improvement:
  550 requests per second after this commit
  510 requests per second with old method_missing technique

On MRI (8% improvement):
  430 requests per second after this commit
  400 requests per second with old method_missing technique
  • Loading branch information...
commit 4f043a48381c142e308824e3b7e15435a61bbb53 1 parent f4f8923
@wycats wycats authored
Showing with 2 additions and 6 deletions.
  1. +2 −6 actionpack/lib/action_controller/mime_responds.rb
8 actionpack/lib/action_controller/mime_responds.rb
@@ -147,13 +147,9 @@ def any(*args, &block)
def self.generate_method_for_mime(mime)
sym = mime.is_a?(Symbol) ? mime : mime.to_sym
const = sym.to_s.upcase
- class_eval <<-RUBY
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{sym}(&block) # def html(&block)
- if Mime::SET.include?(Mime::#{const}) # if Mime::Set.include?(Mime::HTML)
- custom(Mime::#{const}, &block) # custom(Mime::HTML, &block)
- else # else
- super # super
- end # end
+ custom(Mime::#{const}, &block) # custom(Mime::HTML, &block)
end # end

6 comments on commit 4f043a4


Another thing you might want to benchmark is using something like:

def #{sym} custom(Mime::#{const}) { |format| yield(format) } end

In DM we benchmarked this as faster than using &block explicitly.


There is a wycats in my railz.

Help pls.


dkubb has a great idea. Anytime that you use &block ruby makes a new Proc from the parameter, even when no block is given. This can slow you down.


Not always.


We actually already do that optimisation with active record (for count, all, etc) and it did make a difference there, but as pratik mentions it’s not quite so simple.

There’s also some subtle differences between the two with some uses (have a look at the core list around september).

If the benchmarks show it faster here, let’s go for it. but it’s not ‘free performance’


Hmm, going to have to do a little research to figure out when it is better and when it is not.

Please sign in to comment.
Something went wrong with that request. Please try again.