Improve Spec Performance for Feature Flag Services
What does this MR do?
Refactor feature flag service specs to use let_it_be
.
Contributes to #251358 (closed) and https://gitlab.com/gitlab-org/plan/-/issues/145.
Running FPROF=1 rspec spec/services/feature_flags/*_spec.rb
gave the following improvements:
-
Total
amount of factories created went down from 218 to 66🚀 -
Total events
went down from 8620 to 2361 - Queries saved: 6259
Before
Total time: 00:10.803 of 00:20.230 (53.4%)
Total events: 8620
Top 5 slowest suites (by time):
FeatureFlags::UpdateService (./spec/services/feature_flags/update_service_spec.rb:5) – 00:05.227 (4284 / 22) of 00:09.721 (53.77%)
FeatureFlags::CreateService (./spec/services/feature_flags/create_service_spec.rb:5) – 00:01.620 (1284 / 7) of 00:03.015 (53.74%)
FeatureFlags::EnableService (./spec/services/feature_flags/enable_service_spec.rb:5) – 00:01.469 (1219 / 9) of 00:02.711 (54.2%)
FeatureFlags::DestroyService (./spec/services/feature_flags/destroy_service_spec.rb:5) – 00:01.456 (1133 / 6) of 00:02.621 (55.56%)
FeatureFlags::DisableService (./spec/services/feature_flags/disable_service_spec.rb:5) – 00:01.029 (700 / 5) of 00:02.160 (47.67%)
Finished in 27.54 seconds (files took 2.45 seconds to load)
49 examples, 0 failures
Randomized with seed 15477
[TEST PROF INFO] Factories usage
Total: 218
Total top-level: 169
Total time: 12.3449s
Total uniq factories: 6
total top-level total time time per call top-level time name
72 72 2.6775s 0.0372s 2.6775s user
49 49 8.2914s 0.1692s 8.2914s project
49 0 2.0746s 0.0423s 0.0000s namespace
36 36 1.3040s 0.0362s 1.3040s operations_feature_flag
7 7 0.0405s 0.0058s 0.0405s operations_feature_flag_scope
5 5 0.0316s 0.0063s 0.0316s license
After
Total time: 00:02.932 of 00:05.905 (49.66%)
Total events: 2361
Top 5 slowest suites (by time):
FeatureFlags::UpdateService (./spec/services/feature_flags/update_service_spec.rb:5) – 00:01.541 (992 / 22) of 00:02.997 (51.43%)
FeatureFlags::EnableService (./spec/services/feature_flags/enable_service_spec.rb:5) – 00:00.431 (428 / 9) of 00:00.844 (51.02%)
FeatureFlags::DestroyService (./spec/services/feature_flags/destroy_service_spec.rb:5) – 00:00.382 (340 / 6) of 00:00.682 (56.08%)
FeatureFlags::CreateService (./spec/services/feature_flags/create_service_spec.rb:5) – 00:00.309 (337 / 7) of 00:00.835 (37.1%)
FeatureFlags::DisableService (./spec/services/feature_flags/disable_service_spec.rb:5) – 00:00.266 (264 / 5) of 00:00.544 (48.99%)
Finished in 13.5 seconds (files took 2.66 seconds to load)
49 examples, 0 failures
Randomized with seed 25398
[TEST PROF INFO] Factories usage
Total: 66
Total top-level: 61
Total time: 3.0531s
Total uniq factories: 6
total top-level total time time per call top-level time name
36 36 1.3469s 0.0374s 1.3469s operations_feature_flag
8 8 0.3164s 0.0396s 0.3164s user
7 7 0.0383s 0.0055s 0.0383s operations_feature_flag_scope
5 5 0.0831s 0.0166s 0.0831s license
5 5 1.2683s 0.2537s 1.2683s project
5 0 0.2805s 0.0561s 0.0000s namespace
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
- [-] Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process.
- [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Peter Leitzen