Skip to content

Speed up project helper specs

Peter Leitzen requested to merge pl-spec-helpers-project-perf into master

What does this MR do?

This MR improves the performance of project helper specs by using let_it_be.

Related to &3752.

Contributes to https://gitlab.com/gitlab-org/plan/-/issues/145.

Here's the output from test-prof when run with FPROF=1. Note:

  • Total amount of factories created went down from 371 to 47 🚀
  • Total events went down from 11158 to 2961
  • Queries saved: 8197

Before

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 00:17.339 of 00:40.446 (42.87%)
Total events: 11158

Top 5 slowest suites (by time):

ProjectsHelper (./spec/helpers/projects_helper_spec.rb:5) – 00:17.339 (11158 / 149) of 00:40.446 (42.87%)



Finished in 47.16 seconds (files took 1.83 seconds to load)
149 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 371
 Total top-level: 191
 Total time: 32.4055s
 Total uniq factories: 14

   total   top-level     total time      time per call      top-level time               name

     127          97       33.2910s            0.2621s            26.8751s            project
     125           1        6.5940s            0.0528s             0.0392s          namespace
      73          71        3.5822s            0.0491s             3.5025s               user
      24           0        6.0506s            0.2521s             0.0000s project_auto_devops
       6           6        1.5790s            0.2632s             1.5790s     project_member
       5           5        0.1585s            0.0317s             0.1585s              group
       3           3        0.0552s            0.0184s             0.0552s grafana_integration
       2           2        0.0401s            0.0200s             0.0401s project_error_tracking_setting
       1           1        0.0128s            0.0128s             0.0128s            license
       1           1        0.0079s            0.0079s             0.0079s project_incident_management_setting
       1           1        0.0400s            0.0400s             0.0400s        ci_pipeline
       1           1        0.0547s            0.0547s             0.0547s       personal_key
       1           1        0.0200s            0.0200s             0.0200s              email
       1           1        0.0206s            0.0206s             0.0206s project_metrics_setting

After

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 00:04.954 of 00:15.623 (31.71%)
Total events: 2961

Top 5 slowest suites (by time):

ProjectsHelper (./spec/helpers/projects_helper_spec.rb:5) – 00:04.954 (2961 / 149) of 00:15.623 (31.71%)



Finished in 21.42 seconds (files took 1.76 seconds to load)
149 examples, 0 failures

Randomized with seed 12385

[TEST PROF INFO] Factories usage

 Total: 47
 Total top-level: 33
 Total time: 4.0010s
 Total uniq factories: 14

   total   top-level     total time      time per call      top-level time               name

      11           8        2.9207s            0.2655s             2.3247s            project
      10           8        0.6624s            0.0662s             0.5342s               user
       8           0        0.5589s            0.0699s             0.0000s          namespace
       5           5        0.2006s            0.0401s             0.2006s              group
       3           3        0.0538s            0.0179s             0.0538s grafana_integration
       2           2        0.6565s            0.3283s             0.6565s     project_member
       1           1        0.0130s            0.0130s             0.0130s            license
       1           1        0.0388s            0.0388s             0.0388s              email
       1           1        0.0661s            0.0661s             0.0661s       personal_key
       1           1        0.0070s            0.0070s             0.0070s project_incident_management_setting
       1           1        0.0307s            0.0307s             0.0307s project_error_tracking_setting
       1           0        0.2696s            0.2696s             0.0000s project_auto_devops
       1           1        0.0565s            0.0565s             0.0565s        ci_pipeline
       1           1        0.0192s            0.0192s             0.0192s project_metrics_setting

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

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

Merge request reports