# Using partials - performance impact

**URL:** <https://www.ruby-forum.com/t/using-partials-performance-impact/92921>\
**Category:** Rails\
**Created:** [April 25, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/using-partials-performance-impact/92921 "2007-04-25T18:19:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [April 25, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/using-partials-performance-impact/92921/1 "2007-04-25T18:19:39Z")

</div>

I love partials – no question about how you can logically separate the  
components of a view and of re-use it in many places.

My question to the experts is - what (if any) performance impact does  
this have in production environment? It can’t be all good news right? Or  
is it?

For example -

Case 1 : All the view rhtml is stored in one file - no partials

Case 2 : The same rhtml is generated using 10 partials with objects  
passed into partials using :locals.

Note that the end result of case 1 and case 2 is the exact same html.

How does case 1 compare with case 2? I do hope to do some tests and will  
share results with the forum.

Thanks.

JR

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [April 26, 2007, 6:41am UTC](https://www.ruby-forum.com/t/using-partials-performance-impact/92921/2 "2007-04-26T06:41:41Z")

</div>

Jason R. wrote:

> My question to the experts is - what (if any) performance impact does  
> this have in production environment? It can’t be all good news right? Or  
> is it?

There is some file IO associated with reading more than one file. I  
would recommend using partial where it makes logical sense.

Let us know what your testing reveals.

Sandy –

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [April 26, 2007, 9:37am UTC](https://www.ruby-forum.com/t/using-partials-performance-impact/92921/3 "2007-04-26T09:37:16Z")

</div>

Good questions. While my test isnt the most detailed and doesnt have  
10 different partials (only 2) It does demonstrate a “slight” speed  
increase for straight rhtml.  
I tested straight rhtml, partial with a collection and partial with  
local. The html for th collection is a little different…too lazy to  
fix.  
Feel free to take the app and modify it to make the test more  
detailed. You can download the app here:  
[http://www.tangofoxtrot.com/assets/2007/4/26/partial\_test.zip](http://www.tangofoxtrot.com/assets/2007/4/26/partial_test.zip)  
Uses sqlite3 and railsbench.

I tested using railsbench perf\_run 200 -bm=main\_controller

the results:

loading environment 2.06392

page request total stddev% r/s ms/r  
main\_index 3.94083 9.4458 50.75 19.70  
main\_collection\_index 4.41511 7.0973 45.30 22.08  
main\_local\_index 4.24100 6.4577 47.16 21.21

all requests 12.59695 7.1636 47.63 20.99

- Richard

On Apr 25, 9:19 am, Jason R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
