Skip to content

Speed up notification service specs

Peter Leitzen requested to merge pl-spec-notifications-perf into master

What does this MR do?

This MR improves the performance of notification service specs by using let_it_be and before_all where applicable.

Related to &3752.

Contributes to #241148 and 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 1782 to 1183 🚀
  • Total events went down from 125619 to 97202
  • Queries saved: 28417

Before

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 02:49.398 of 06:50.545 (41.26%)
Total events: 125619

Top 5 slowest suites (by time):

NotificationService (./spec/services/notification_service_spec.rb:5) – 02:49.398 (125619 / 322) of 06:50.545 (41.26%)



Finished in 6 minutes 58 seconds (files took 45.5 seconds to load)
322 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 1782
 Total top-level: 1566
 Total time: 108.3045s
 Total uniq factories: 34

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

    1092        1046       49.6143s            0.0454s            47.3685s               user
     119         117       12.0096s            0.1009s            11.7990s              issue
     111          74       23.5936s            0.2126s            16.9523s            project
      96          96       18.4965s            0.1927s            18.4965s      merge_request
      90           3        4.7744s            0.0530s             0.1091s          namespace
      78          78        4.7160s            0.0605s             4.7160s              group
      53          53        2.3269s            0.0439s             2.3269s      note_on_issue
      28          28        1.0703s            0.0382s             1.0703s        ci_pipeline
      24           4        0.3722s            0.0155s             0.0852s              label
      22           2        0.2567s            0.0117s             0.0335s        group_label
       7           7        0.2652s            0.0379s             0.2652s          milestone
       6           6        0.3550s            0.0592s             0.3550s              admin
       6           6        0.1366s            0.0228s             0.1366s note_on_personal_snippet
       6           6        0.4990s            0.0832s             0.4990s diff_note_on_merge_request
       5           5        0.1234s            0.0247s             0.1234s               note
       5           5        0.1509s            0.0302s             0.1509s     note_on_commit
       4           4        1.3885s            0.3471s             1.3885s     project_member
       3           3        0.0456s            0.0152s             0.0456s              email
       3           3        0.0308s            0.0103s             0.0308s notification_setting
       3           0        0.5804s            0.1935s             0.0000s project_auto_devops
       3           3        0.0536s            0.0179s             0.0536s      remote_mirror
       3           3        0.2771s            0.0924s             0.2771s   prometheus_alert
       3           3        0.0198s            0.0066s             0.0198s             review
       2           2        1.1796s            0.5898s             1.1796s            gpg_key
       1           1        0.0067s            0.0067s             0.0067s            license
       1           1        0.0824s            0.0824s             0.0824s       personal_key
       1           1        0.0397s            0.0397s             0.0397s    project_snippet
       1           1        0.0465s            0.0465s             0.0465s note_on_project_snippet
       1           1        0.0253s            0.0253s             0.0253s   personal_snippet
       1           1        0.2312s            0.2312s             0.2312s             design
       1           1        0.1828s            0.1828s             0.1828s diff_note_on_design
       1           1        0.1945s            0.1945s             0.1945s            release
       1           0        0.0325s            0.0325s             0.0000s             author
       1           1        0.0129s            0.0129s             0.0129s       pages_domain

After

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 02:24.498 of 05:50.158 (41.27%)
Total events: 97202

Top 5 slowest suites (by time):

NotificationService (./spec/services/notification_service_spec.rb:5) – 02:24.498 (97202 / 322) of 05:50.158 (41.27%)



Finished in 5 minutes 57 seconds (files took 2.2 seconds to load)
322 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 1183
 Total top-level: 1007
 Total time: 84.1653s
 Total uniq factories: 34

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

     621         575       31.7811s            0.0512s            29.7949s               user
     105         103       11.5234s            0.1097s            11.3166s              issue
      94          94       18.4950s            0.1968s            18.4950s      merge_request
      71          34       16.4075s            0.2311s            10.0686s            project
      62          62        4.6546s            0.0751s             4.6546s              group
      50           3        3.0635s            0.0613s             0.1558s          namespace
      43          43        2.4016s            0.0559s             2.4016s      note_on_issue
      28          28        1.1159s            0.0399s             1.1159s        ci_pipeline
      24           4        0.4188s            0.0175s             0.1221s              label
      22           2        0.4214s            0.0192s             0.0454s        group_label
       7           7        0.3517s            0.0502s             0.3517s          milestone
       6           6        0.3676s            0.0613s             0.3676s              admin
       6           6        0.1326s            0.0221s             0.1326s note_on_personal_snippet
       5           5        0.1168s            0.0234s             0.1168s               note
       4           4        0.4686s            0.1172s             0.4686s diff_note_on_merge_request
       4           4        1.2228s            0.3057s             1.2228s     project_member
       3           3        0.0634s            0.0211s             0.0634s              email
       3           3        0.0451s            0.0150s             0.0451s notification_setting
       3           0        0.6076s            0.2025s             0.0000s project_auto_devops
       3           3        0.0504s            0.0168s             0.0504s      remote_mirror
       3           3        0.1800s            0.0600s             0.1800s   prometheus_alert
       3           3        0.0227s            0.0076s             0.0227s             review
       2           2        2.0020s            1.0010s             2.0020s            gpg_key
       1           1        0.0069s            0.0069s             0.0069s            license
       1           1        0.0693s            0.0693s             0.0693s       personal_key
       1           1        0.0446s            0.0446s             0.0446s    project_snippet
       1           1        0.0573s            0.0573s             0.0573s note_on_project_snippet
       1           1        0.0302s            0.0302s             0.0302s   personal_snippet
       1           1        0.1719s            0.1719s             0.1719s     note_on_commit
       1           1        0.2042s            0.2042s             0.2042s             design
       1           1        0.1786s            0.1786s             0.1786s diff_note_on_design
       1           1        0.1819s            0.1819s             0.1819s            release
       1           0        0.0296s            0.0296s             0.0000s             author
       1           1        0.0263s            0.0263s             0.0263s       pages_domain

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