Skip to content

Speed up CI trace lib specs

Peter Leitzen requested to merge pl-spec-ci-trace-perf into master

What does this MR do?

This MR improves the performance of CI trace lib specs by using let_it_be and FactoryDefault 🎉

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 476 to 84 🚀
  • Total events went down from 10870 to 1794
  • Queries saved: 9076

Noticed during review of !44424 (merged).

Before

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 00:16.679 of 00:33.649 (49.57%)
Total events: 10870

Top 5 slowest suites (by time):

Gitlab::Ci::Trace (./spec/lib/gitlab/ci/trace_spec.rb:5) – 00:16.679 (10870 / 114) of 00:33.649 (49.57%)



Finished in 40.85 seconds (files took 1.77 seconds to load)
114 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 476
 Total top-level: 129
 Total time: 31.4522s
 Total uniq factories: 6

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

     114         114       31.2472s            0.2741s            31.2472s           ci_build
     114           0       27.2019s            0.2386s             0.0000s        ci_pipeline
     114           0       23.6495s            0.2075s             0.0000s            project
     114           0        5.9074s            0.0518s             0.0000s          namespace
      19          14        0.2916s            0.0153s             0.1983s    ci_job_artifact
       1           1        0.0067s            0.0067s             0.0067s            license

After

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 00:02.377 of 00:05.840 (40.7%)
Total events: 1794

Top 5 slowest suites (by time):

Gitlab::Ci::Trace (./spec/lib/gitlab/ci/trace_spec.rb:5) – 00:02.377 (1794 / 114) of 00:05.840 (40.7%)



Finished in 13.28 seconds (files took 1.75 seconds to load)
114 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 84
 Total top-level: 47
 Total time: 3.0622s
 Total uniq factories: 6

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

      31          31        2.3306s            0.0752s             2.3306s           ci_build
      31           0        0.7242s            0.0234s             0.0000s        ci_pipeline
      19          14        0.3514s            0.0185s             0.2577s    ci_job_artifact
       1           1        0.0081s            0.0081s             0.0081s            license
       1           1        0.4659s            0.4659s             0.4659s            project
       1           0        0.0994s            0.0994s             0.0000s          namespace

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