Skip to content

Use execute_batch2 rather than execute_batch to fix performance regression for fixture loading - #35844

Merged
kamipo merged 1 commit into
rails:masterfrom
kamipo:fix_fixture_loading_performance_regression
Apr 3, 2019
Merged

kamipo merged 1 commit into
rails:masterfrom
kamipo:fix_fixture_loading_performance_regression

Conversation

@kamipo

@kamipo kamipo commented Apr 3, 2019

Copy link
Copy Markdown
Member

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

What do you think?

…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 eileencodes left a comment

Copy link
Copy Markdown
Member

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 kaspth left a comment

Copy link
Copy Markdown
Contributor

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!

@kamipo
kamipo merged commit 9bccf46 into rails:master Apr 3, 2019
@kamipo
kamipo deleted the fix_fixture_loading_performance_regression branch April 3, 2019 19:00
require "active_record/connection_adapters/sqlite3/schema_statements"

gem "sqlite3", "~> 1.3", ">= 1.3.6"
gem "sqlite3", "~> 1.4"

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown

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.

mracos added a commit to heartcombo/devise that referenced this pull request May 4, 2019
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
mracos added a commit to heartcombo/devise that referenced this pull request May 4, 2019
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
y-yagi added a commit to y-yagi/enumerize that referenced this pull request May 25, 2019
Also, moved sqlite3 gem to individual gemfiles because Rails 6 requires
sqlite3 upper 1.4.0.
Ref: rails/rails#35844
jtapia pushed a commit to jtapia/devise that referenced this pull request Jun 6, 2019
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
mygreatstory pushed a commit to mygreatstory/rubenumerize that referenced this pull request Jan 9, 2021
Also, moved sqlite3 gem to individual gemfiles because Rails 6 requires
sqlite3 upper 1.4.0.
Ref: rails/rails#35844
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants