rails/rails — pull request #12090 by njakobsen (2013-08-30 20:15:03+00:00)
Title: [Performance] Don't create fibers while merging bind variables

Master branch has a serious performance regression when including objects for a relation. e.g. ```Item.includes(:people)```.

The regression is caused by the use of an iterator in the relation merger.rb, see https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/merger.rb#L110

This causes ruby to create many fibers while iterating, when the same effect could be achieved by changing how the bind_values enumerable is accessed. See pull request.

Here are my test results for my own project
```
Rails 3.2.13
Item.include(:people).limit(1000) #=> 1.049828

Rails 4 4-0-stable
Item.include(:people).limit(1000) #=> 3.609199

Rails 4 master
Item.include(:people).limit(1000) #=> 31.08081

Rails 4 master with optimization (pull request)
Item.include(:people).limit(1000) #=> 2.134169
```

Use the following gist to test performance on various versions of rails.
https://gist.github.com/njakobsen/6393783