Created
May 31, 2010 20:00
-
-
Save sudara/420210 to your computer and use it in GitHub Desktop.
bloat_fail.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## FAIL | |
| ## Attempting to iterate (chunkily) over 2000 records and instantiating 1 single object per iteration | |
| ## All of the below bloat to > 200MB on rails 2.3.x | |
| # iterates in chunks of 10 | |
| User.find_each(:batch_size => 10) do |user| | |
| date = user.posts.find(:first).created_at | |
| end | |
| # iterates in chunks of 100 | |
| User.find_each(:batch_size => 10) do |user| | |
| date = user.posts.find(:first).created_at | |
| end | |
| # iterates with will_paginate | |
| User.paginated_each do |user| | |
| date = user.posts.find(:first).created_at | |
| end | |
| # Not going through the relationship doesn't make a difference | |
| User.find_each(:batch_size => 10) do |user| | |
| date = Posts.find(:first, :conditions =>{:user => user}).created_at | |
| end | |
| # Nor does storing the result in a var with a larger scope | |
| date = [] | |
| User.find_each(:batch_size => 10) do |user| | |
| date << user.posts.find(:first).created_at | |
| end | |
| # Or heck, not storing the result at all | |
| User.find_each(:batch_size => 10) do |user| | |
| user.posts.find(:first).created_at | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment