# Performance regression in activerecord scoping

**URL:** <https://community.rubybench.org/t/performance-regression-in-activerecord-scoping/74>\
**Category:** Uncategorized\
**Created:** [June 8, 2015, 4:42pm UTC](https://community.rubybench.org/t/performance-regression-in-activerecord-scoping/74 "2015-06-08T16:42:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![klgilbert](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@klgilbert](https://community.rubybench.org/u/klgilbert)\
**Post date:** [June 8, 2015, 4:42pm UTC](https://community.rubybench.org/t/performance-regression-in-activerecord-scoping/74/1 "2015-06-08T16:42:38Z")

</div>

I opened this [issue](https://github.com/rails/rails/issues/20418) on the performance regression with scoping in the new release of rails from 4.2. I ran memory profiler on [4.1.10](http://pastebin.com/cWhLrMM7) and [4.2.0](http://pastebin.com/E2BjFfDt).

It’s only portion of the output from memory profiler, but how do the results look?

For example, I noticed that in 4.1.10 allocated memory for query\_methods.rb was about 66 MB, but then in 4.2.0 it jumped to 162 MB.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/rubybench/original/1X/4ae23b7eff9a1b039e126f05dd734ab09c8ab4b5.png) [@system](https://community.rubybench.org/u/system)\
**Post date:** [June 8, 2015, 11:32pm UTC](https://community.rubybench.org/t/performance-regression-in-activerecord-scoping/74/2 "2015-06-08T23:32:10Z")

</div>

Could you post the diff of that method between 4.1.10 against 4.2.0? 😃

---

<div class="post-metadata">

**Author:** ![klgilbert](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@klgilbert](https://community.rubybench.org/u/klgilbert)\
**Post date:** [June 9, 2015, 1:01am UTC](https://community.rubybench.org/t/performance-regression-in-activerecord-scoping/74/3 "2015-06-09T01:01:02Z")

</div>

Here’s a paste bin [4.1.10 4.2.0 diff on query\_methods.rb - Pastebin.com](http://pastebin.com/wPBygu1M)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/rubybench/original/1X/4ae23b7eff9a1b039e126f05dd734ab09c8ab4b5.png) [@system](https://community.rubybench.org/u/system)\
**Post date:** [June 9, 2015, 2:07am UTC](https://community.rubybench.org/t/performance-regression-in-activerecord-scoping/74/4 "2015-06-09T02:07:38Z")

</div>

Ok lets zoom in further. Now we know the file that is taking up more memory, we need to figure out which change in that file is the culprit. 😄

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/rubybench/original/1X/4ae23b7eff9a1b039e126f05dd734ab09c8ab4b5.png) [@system](https://community.rubybench.org/u/system)\
**Post date:** [June 9, 2015, 1:18pm UTC](https://community.rubybench.org/t/performance-regression-in-activerecord-scoping/74/5 "2015-06-09T13:18:47Z")

</div>

Btw be sure to benchmark against Rails head too. We might be doing all the work here when Rails head has already recovered the performance.

---

<div class="post-metadata">

**Author:** ![klgilbert](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@klgilbert](https://community.rubybench.org/u/klgilbert)\
**Post date:** [June 12, 2015, 2:34am UTC](https://community.rubybench.org/t/performance-regression-in-activerecord-scoping/74/6 "2015-06-12T02:34:59Z")

</div>

Seems like that’s the case since memory usage for query\_methods.rb decreased when testing against master, but at the same time it feels like my tests are off.
