<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR><DIV><DIV>On May 19, 2007, at 10:53 PM, Tony Arcieri wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite">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) <BR><BR>Nevertheless, the general vibe is: don't use components, and expect them to go away<BR><BR>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" <BR><BR>- Tony<BR><BR><DIV><BLOCKQUOTE class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><DIV><SPAN class="e" id="q_112a7d32af3d1853_2"><DIV><BLOCKQUOTE class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><BR class="khtml-block-placeholder"></BLOCKQUOTE></DIV></SPAN></DIV></BLOCKQUOTE></DIV> </BLOCKQUOTE></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>hi tony-</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>i've been unable to show that components are, in fact, slower:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>### a simple controller</DIV><DIV>cfp:~/src/ruby/componentry/componentry-0.0.0/sample/rails > cat app/controllers/bar_controller.rb </DIV><DIV>class BarController < ApplicationController</DIV><DIV> def initialize</DIV><DIV> @foo = 42</DIV><DIV> @bar = 'forty-two'</DIV><DIV> end</DIV><DIV> def foo</DIV><DIV> render :text => @foo</DIV><DIV> end</DIV><DIV> def bar </DIV><DIV> render :text => @bar</DIV><DIV> end</DIV><DIV> def foobar</DIV><DIV> render :text => [@foo, @bar].inspect #=> [42, "forty-two"] </DIV><DIV> end</DIV><DIV>end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>### benchmarking</DIV><DIV>cfp:~/src/ruby/componentry/componentry-0.0.0/sample/rails > ab -n 25 -c 4 <A href="http://localhost:3000/bar/foobar|grep">http://localhost:3000/bar/foobar|grep</A> 'Requests'</DIV><DIV>Requests per second: 7.05 [#/sec] (mean)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>### another controller which uses the simple controller above via component_for (see attached code)</DIV><DIV>cfp:~/src/ruby/componentry/componentry-0.0.0/sample/rails > cat app/controllers/foo_controller.rb </DIV><DIV>class FooController < ApplicationController</DIV><DIV> def foobar </DIV><DIV> # get a handle on, and parameterize, a bar controller</DIV><DIV> bar_controller = component_for(:controller => 'bar') do</DIV><DIV> @foo = 42</DIV><DIV> @bar = 'forty-two' </DIV><DIV> end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV> # call two actions on the bar controller, reusing the entire model+view+controller</DIV><DIV> foo = bar_controller.content_for :action => 'foo'</DIV><DIV> bar = bar_controller.content_for :action => 'bar'</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV> render :text => [foo, bar].inspect #=> [42, "forty-two"] </DIV><DIV> end</DIV><DIV>end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>### benchmarking</DIV><DIV>cfp:~/src/ruby/componentry/componentry-0.0.0/sample/rails > ab -n 25 -c 4 <A href="http://localhost:3000/foo/foobar|grep">http://localhost:3000/foo/foobar|grep</A> 'Requests'</DIV><DIV>Requests per second: 6.79 [#/sec] (mean)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>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.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>ps. above is using lighttpd, perhaps mongrel would have issues with concurrency?</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>cheers.</DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>-a</DIV><DIV>--</DIV><DIV>we can deny everything, except that we have the possibility of being better. simply reflect on that.</DIV><DIV>h.h. the 14th dalai lama</DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR class="Apple-interchange-newline"></SPAN></SPAN></SPAN></SPAN> </DIV><BR></BODY></HTML>