Skip to content

Speed up member model specs

Peter Leitzen requested to merge pl-perf-spec-models-member into master

What does this MR do?

This MR improves the performance of model specs for member by using let_it_be and before_all and reusing created factories.

Related to &3752.

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

  • Total amount of factories created went down from 926 to 216 🚀
  • Speed improvement from ~1m48s down to ~33s (mostly due to the use of before_all) 🚀

Before

Finished in 1 minute 48.08 seconds (files took 2.1 seconds to load)
162 examples, 0 failures, 2 pending

[TEST PROF INFO] Factories usage

 Total: 926
 Total top-level: 680
 Total time: 60.5101s
 Total uniq factories: 10

   total   top-level   total time   top-level time                           name

     419         322     20.6106s         15.2002s                           user
     116         116     18.1072s         18.1072s                 project_member
     115           0      5.9480s          0.0000s                      namespace
      87          64     19.1069s         13.9857s                        project
      62          51      1.8079s          1.4181s                          group
      56          56      2.6229s          2.6229s                          admin
      28          28      6.5278s          6.5278s                        project
      28          28      1.0579s          1.0579s                          group
      14          14      1.5795s          1.5795s                   group_member
       1           1      0.0108s          0.0108s                        license

Total sql.active_record events: 32380

After

Finished in 33.75 seconds (files took 2.1 seconds to load)
162 examples, 0 failures, 2 pending

[TEST PROF INFO] Factories usage

 Total: 216
 Total top-level: 128
 Total time: 16.6739s
 Total uniq factories: 10

   total   top-level   total time   top-level time                           name

      59          50      2.7993s          2.3520s                           user
      45           0      2.2344s          0.0000s                      namespace
      43          20      9.8907s          4.5345s                        project
      28          28      7.6322s          7.6322s                 project_member
      18           7      0.4902s          0.2161s                          group
      14          14      1.3406s          1.3406s                   group_member
       4           4      0.1637s          0.1637s                          admin
       2           2      0.3709s          0.3709s                        project
       2           2      0.0541s          0.0541s                          group
       1           1      0.0099s          0.0099s                        license

Total sql.active_record events: 9047

Queries saved: 23333

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 John Hope

Merge request reports