title: When to use memoization in Ruby on Rails
body: <p>In mid July 2008 Memoization was added to Rails core. A demonstration of the usage is <a href="http://www.railway.at/articles/2008/09/20/a-guide-to-memoization" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I have not been able to find any good examples on when methods should be memoized, and the performance implications of each. <a href="http://blog.purepistos.net/index.php/2008/09/29/rails-memoization-is-not-always-faster/" rel="nofollow noreferrer">This blog post</a>, for example, suggests that oftentimes, memoization should not be used at all.</p>
  
  <p>For something that could potentially have tremendous performance implications, there seem to be few resources that go beyond providing a simple tutorial.</p>
  
  <p>Has anyone seen memoization used in their own projects? What factors would make you consider memoizing a method?</p>
  
  <hr>
  
  <p>After doing some more research on my own I found that memoization is used a remarkable number of times inside of Rails core.</p>
  
  <p>Here's an example: <a href="http://github.com/rails/rails/blob/1182658e767d2db4a46faed35f0b1075c5dd9a88/actionpack/lib/action_view/template.rb" rel="nofollow noreferrer">http://github.com/rails/rails/blob/1182658e767d2db4a46faed35f0b1075c5dd9a88/actionpack/lib/action_view/template.rb</a>.</p>
  
  <p>This usage seems to go against the findings of the blog post above that found memoization can hurt performance.</p>