Improve performance of project filter_by_feature_visibility spec
What does this MR do and why?
This MR improves performance for Project.filter_by_feature_visibility spec by using let_it_be_with_reload
combined with update!
to avoid repetitive project factory creations.
See similar improvements in !78333 (merged), !78334 (merged), and !78377 (merged).
How to set up and validate locally
bin/rspec spec/models/project_spec.rb -e ".filter_by_feature_visibility"
RSpec Profiling
Here's the output from test-prof
when run with FPROF=1
. Note:
-
Total amount
of factories created went down from 476 to 142🚀 -
Total events
went down from 16643 to 10032 - Queries saved: 6611
Before
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:43.548 of 01:47.171 (40.63%)
Total events: 16643
Top 5 slowest suites (by time):
Project (./spec/models/project_spec.rb:5) – 00:43.548 (16643 / 168) of 01:47.171 (40.63%)
Finished in 2 minutes 10.4 seconds (files took 40.17 seconds to load)
168 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 476
Total top-level: 307
Total time: 01:23.899 (out of 02:40.724)
Total uniq factories: 6
total top-level total time time per call top-level time name
304 136 36.6579s 0.1206s 15.8729s user
168 168 66.6545s 0.3968s 66.6545s project
1 1 0.0281s 0.0281s 0.0281s license
1 1 0.8810s 0.8810s 0.8810s namespace
1 1 0.4630s 0.4630s 0.4630s group
1 0 0.0323s 0.0323s 0.0000s namespace_settings
After
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:18.727 of 00:46.715 (40.09%)
Total events: 10032
Top 5 slowest suites (by time):
Project (./spec/models/project_spec.rb:5) – 00:18.727 (10032 / 168) of 00:46.715 (40.09%)
Finished in 56.19 seconds (files took 13 seconds to load)
168 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 142
Total top-level: 140
Total time: 00:17.738 (out of 01:06.162)
Total uniq factories: 6
total top-level total time time per call top-level time name
137 136 12.9409s 0.0945s 12.8525s user
1 1 0.0075s 0.0075s 0.0075s license
1 1 0.3229s 0.3229s 0.3229s namespace
1 1 0.1610s 0.1610s 0.1610s group
1 0 0.0134s 0.0134s 0.0000s namespace_settings
1 1 4.3943s 4.3943s 4.3943s project
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Peter Leitzen