-
Notifications
You must be signed in to change notification settings - Fork 22.2k
Use execute_batch2 rather than execute_batch to fix performance regression for fixture loading
#35844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use execute_batch2 rather than execute_batch to fix performance regression for fixture loading
#35844
Conversation
…egression for fixture loading d8d6bd5 makes fixture loading to bulk statements by using `execute_batch` for sqlite3 adapter. But `execute_batch` is slower and it caused the performance regression for fixture loading. In sqlite3 1.4.0, it have new batch method `execute_batch2`. I've confirmed `execute_batch2` is extremely faster than `execute_batch`. So I think it is worth to upgrade sqlite3 to 1.4.0 to use that method. Before: ``` % ARCONN=sqlite3 bundle exec ruby -w -Itest test/cases/associations/eager_test.rb -n test_eager_loading_too_may_ids Using sqlite3 Run options: -n test_eager_loading_too_may_ids --seed 35790 # Running: . Finished in 202.437406s, 0.0049 runs/s, 0.0049 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips ARCONN=sqlite3 bundle exec ruby -w -Itest -n test_eager_loading_too_may_ids 142.57s user 60.83s system 98% cpu 3:27.08 total ``` After: ``` % ARCONN=sqlite3 bundle exec ruby -w -Itest test/cases/associations/eager_test.rb -n test_eager_loading_too_may_ids Using sqlite3 Run options: -n test_eager_loading_too_may_ids --seed 16649 # Running: . Finished in 8.471032s, 0.1180 runs/s, 0.1180 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips ARCONN=sqlite3 bundle exec ruby -w -Itest -n test_eager_loading_too_may_ids 10.71s user 1.36s system 95% cpu 12.672 total ```
eileencodes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick fix ❤️
kaspth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the build passed too!
| require "active_record/connection_adapters/sqlite3/schema_statements" | ||
|
|
||
| gem "sqlite3", "~> 1.3", ">= 1.3.6" | ||
| gem "sqlite3", "~> 1.4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add changelog entry to note that Active Record is compatible with sqlite3 ~> 1.4 since Rails 6.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This has just caught us out in cucumber-rails as we were using a 1.3 version of sqllite across the board. We'll put a conditional in for rails 6.
Also bumped sqlite from 1.3.6 to 1.4 because besides conflicting with the version that the sqlite adapter was trying to load [0], it is supported officially since rails 6 [1]. Related: [0] rails/rails#35153 [1] rails/rails#35844
Also bumped sqlite from 1.3.6 to 1.4 because besides conflicting with the version that the sqlite adapter was trying to load [0], it is supported officially since rails 6 [1]. Related: [0] rails/rails#35153 [1] rails/rails#35844
Also, moved sqlite3 gem to individual gemfiles because Rails 6 requires sqlite3 upper 1.4.0. Ref: rails/rails#35844
Also bumped sqlite from 1.3.6 to 1.4 because besides conflicting with the version that the sqlite adapter was trying to load [0], it is supported officially since rails 6 [1]. Related: [0] rails/rails#35153 [1] rails/rails#35844
Also, moved sqlite3 gem to individual gemfiles because Rails 6 requires sqlite3 upper 1.4.0. Ref: rails/rails#35844
* Starting in Rails 6, ActiveRecord's Sqlite adapter restricted the
sqlite3 gem version to ~> 1.4. This is still true in Rails 7.1. See
rails/rails#35844.
* Use the same restriction here to ensure a compatible sqlite3 version
is installed for the dev and test.
* The version restriction has been relaxed on Rails edge but it hasn't
landed in a released Rails version yet. See
rails/rails#51592.
d8d6bd5 makes fixture loading to bulk statements by using
execute_batchfor sqlite3 adapter. Butexecute_batchis slower andit caused the performance regression for fixture loading.
In sqlite3 1.4.0, it have new batch method
execute_batch2. I'veconfirmed
execute_batch2is extremely faster thanexecute_batch.So I think it is worth to upgrade sqlite3 to 1.4.0 to use that method.
Before:
After:
What do you think?