You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a performance issue when using preload for a large number of rows. Even though, the request itself may be very fast there is a very large amount of time spent in the Bullet::Rack part. Example code:
The text was updated successfully, but these errors were encountered:
iSarCasm
changed the title
Performance issues when using preload on large amounts of rows
Performance issues when using preload on large number of rows
Feb 8, 2022
iSarCasm
changed the title
Performance issues when using preload on large number of rows
Performance issues when using preload with large number of rows
Feb 8, 2022
Thanks @iSarCasm for sharing this. We are having a similar performance issue for a large amount of records query. In our case it seems like the issue is with the N + 1 query detector.
Issue
There is a performance issue when using
preload
for a large number of rows. Even though, the request itself may be very fast there is a very large amount of time spent in theBullet::Rack
part. Example code:@comments = Comment.preload(:article).first(5_000)
With bullet turned OFF:
Request completed in ~0.6 seconds
![vnd m Other](https://user-images.githubusercontent.com/1886857/152996691-d298ca7e-62a0-4f0e-be42-72be9653c48b.png)
Ruby-Prof flat output:
Full profiling information can be found here: https://github.com/iSarCasm/bullet-performance-app/tree/main/rubyprof
With bullet turned ON:
Request completed in ~10 seconds
![Pasted Graphic](https://user-images.githubusercontent.com/1886857/152996884-ffd3abd3-30d2-4611-8c24-e454aade828a.png)
Ruby-Prof flat output:
Full profiling information can be found here: https://github.com/iSarCasm/bullet-performance-app/tree/main/rubyprof
Steps to reproduce
I have created a sample Rails 7 application with 2 scaffolded models and a seed file hosted here: https://github.com/iSarCasm/bullet-performance-app
It also mentions the full list of steps taken to recreate the problem.
Possible problem
This is probably caused by the
UnusedEagerLoading
detector (https://github.com/flyerhzm/bullet/blob/master/lib/bullet/detector/unused_eager_loading.rb) which seems to have O(n^2) time complexity since there are 25000015Set#merge
invocation which is ~5000*5000
(5000 Comments with 5000 Articles loaded in 2 DB queries).The text was updated successfully, but these errors were encountered: