[Boulder-Denver Ruby Group] re-inventing components
ara.t.howard
ara.t.howard at gmail.com
Sun May 20 09:39:58 EDT 2007
On May 19, 2007, at 10:53 PM, Tony Arcieri wrote:
> In specific regard to render_component, Rails components are
> painfully slow and unofficially deprecated to the point where Rails
> core is silently threatening to remove them (although they probably
> won't, due to their utility)
>
> Nevertheless, the general vibe is: don't use components, and expect
> them to go away
>
> I think something lighter than an entire instance of
> ActionController is definitely in order, and specifically something
> where its creators aren't telling you "Don't use it"
>
> - Tony
>
>
hi tony-
i've been unable to show that components are, in fact, slower:
### 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. do you 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?
cheers.
-a
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/bdrg-members/attachments/20070520/211f27ad/attachment.html
More information about the Bdrg-members
mailing list