Skip to content

Speed up cycle analytics events specs

Peter Leitzen requested to merge pl-spec-lib-cycle-analytics-events-perf into master

What does this MR do?

This MR improves the performance of cycle analytics lib spec by using let_it_be and merging examples into while using aggregate_failures.

Related to &3752.

Contributes to https://gitlab.com/gitlab-org/plan/-/issues/145 (more specifically @lulalala's suggestion: https://gitlab.com/gitlab-org/plan/-/issues/145#note_411920773).

It also contributes to #220040 (closed).

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

  • Total amount of factories created went down from 353 to 23 🚀
  • Total time dropped from ~4 minutes to ~20 seconds by simply running less examples (53 -> 6)
  • Total events went down from 34404 to 3291
  • Queries saved: 31113

Before

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 00:47.055 of 02:24.005 (32.68%)
Total events: 34404

Top 5 slowest suites (by time):

cycle analytics events (./spec/lib/gitlab/cycle_analytics/events_spec.rb:5) – 00:47.055 (34404 / 53) of 02:24.005 (32.68%)



Finished in 4 minutes 17.1 seconds (files took 26.06 seconds to load)
53 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 353
 Total top-level: 300
 Total time: 26.1245s
 Total uniq factories: 8

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

      54          54        3.7168s            0.0688s             3.7168s           ci_build
      53          53       13.0769s            0.2467s            13.0769s            project
      53           0        3.2064s            0.0605s             0.0000s          namespace
      53          53        2.7906s            0.0527s             2.7906s              issue
      53          53        1.9163s            0.0362s             1.9163s          milestone
      53          53        2.9891s            0.0564s             2.9891s               user
      33          33        1.6194s            0.0491s             1.6194s        ci_pipeline
       1           1        0.0153s            0.0153s             0.0153s            license

After

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 00:04.434 of 00:14.901 (29.76%)
Total events: 3291

Top 5 slowest suites (by time):

cycle analytics events (./spec/lib/gitlab/cycle_analytics/events_spec.rb:5) – 00:04.434 (3291 / 6) of 00:14.901 (29.76%)



Finished in 20.58 seconds (files took 2.11 seconds to load)
6 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 24
 Total top-level: 23
 Total time: 2.1482s
 Total uniq factories: 8

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

       6           6        0.3482s            0.0580s             0.3482s              issue
       6           6        0.1708s            0.0285s             0.1708s          milestone
       5           5        0.3279s            0.0656s             0.3279s           ci_build
       3           3        0.1368s            0.0456s             0.1368s        ci_pipeline
       1           1        0.0152s            0.0152s             0.0152s            license
       1           1        1.0896s            1.0896s             1.0896s            project
       1           0        0.2016s            0.2016s             0.0000s          namespace
       1           1        0.0597s            0.0597s             0.0597s               user

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