hi-
contrary to what i've read, i've been unable to show that components are, in fact, slower than any other rendering process:
### a simple controller cfp:~/src/ruby/componentry/componentry-0.0.0/sample/rails > cat app/controllers/bar_controller.rb class BarController < ApplicationController def initialize @foo = 42 @bar = 'forty-two' end def foo render :text => @foo end def bar render :text => @bar end def foobar render :text => [@foo, @bar].inspect #=> [42, "forty-two"] end end
### benchmarking cfp:~/src/ruby/componentry/componentry-0.0.0/sample/rails > ab -n 25 -c 4 http://localhost:3000/bar/foobar|grep 'Requests' Requests per second: 7.05 [#/sec] (mean)
### another controller which uses the simple controller above via component_for (see attached code) cfp:~/src/ruby/componentry/componentry-0.0.0/sample/rails > cat app/controllers/foo_controller.rb class FooController < ApplicationController def foobar # get a handle on, and parameterize, a bar controller bar_controller = component_for(:controller => 'bar') do @foo = 42 @bar = 'forty-two' end
# call two actions on the bar controller, reusing the entire model+view+controller foo = bar_controller.content_for :action => 'foo' bar = bar_controller.content_for :action => 'bar'
render :text => [foo, bar].inspect #=> [42, "forty-two"] end end
### benchmarking cfp:~/src/ruby/componentry/componentry-0.0.0/sample/rails > ab -n 25 -c 4 http://localhost:3000/foo/foobar|grep 'Requests' Requests per second: 6.79 [#/sec] (mean)
so this seems to indicate that the above two routes, with and without components, are essentially the same. does anyone have code showing that they are significantly slower? my reading of the rails source doesn't show any significant work being done when components are used, many objects are dup'd when possible, so this makes sense to me. nonetheless the net is awash with people claiming this is not true.
ps. above is using lighttpd, perhaps mongrel would have issues with concurrency?
kind regards.
-a