Skip to content

Improve performance of search group service spec

Peter Leitzen requested to merge pl-spec-search-group-service-perf into master

What does this MR do?

This MR improves performance for search group service spec by using let_it_be_with_reload combined with update! to avoid repetitive project factory creations.

This cuts the runtime of this spec in half 💃

ee/spec/services/search/group_service_spec.rb is top 3 of specs with most total_queries in https://gitlab-org.gitlab.io/rspec_profiling_stats/.

Screenshot_from_2022-01-16_13-31-28

See also !78334 (merged).

RSpec Profiling

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

  • Total amount of factories created went down from 3829 to 1612 🚀
  • Total events went down from 157631 to 82530
  • Queries saved: 75101

Before

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 05:38.233 of 20:39.444 (27.29%)
Total events: 157631

Top 5 slowest suites (by time):

Search::GroupService (./ee/spec/services/search/group_service_spec.rb:5) – 05:38.233 (157631 / 580) of 20:39.444 (27.29%)



Finished in 20 minutes 52 seconds (files took 17.41 seconds to load)
580 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 3829
 Total top-level: 2265
 Total time: 10:33.293 (out of 21:04.298)
 Total uniq factories: 15

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

    1049        1049      481.3848s            0.4589s           481.3848s            project
     964         475      156.2314s            0.1621s            74.1594s               user
     565           0       92.2690s            0.1633s             0.0000s          namespace
     192         108       30.5015s            0.1589s            17.4542s      merge_request
     192         108       12.2875s            0.0640s             6.9316s              issue
     192           0        2.9541s            0.0154s             0.0000s     work_item_type
     126         126        4.3039s            0.0342s             4.3039s          milestone
      84          84        9.9460s            0.1184s             9.9460s      note_on_issue
      84          84       17.3175s            0.2062s            17.3175s note_on_merge_request
      84          84        5.5355s            0.0659s             5.5355s     note_on_commit
      84          84        9.2889s            0.1106s             9.2889s note_on_project_snippet
      84           0        4.3845s            0.0522s             0.0000s    project_snippet
      64          62        7.1404s            0.1116s             6.9611s              group
      64           0        0.5141s            0.0080s             0.0000s namespace_settings
       1           1        0.0102s            0.0102s             0.0102s            license

After

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 02:15.950 of 09:36.103 (23.6%)
Total events: 82530

Top 5 slowest suites (by time):

Search::GroupService (./ee/spec/services/search/group_service_spec.rb:5) – 02:15.950 (82530 / 580) of 09:36.103 (23.6%)



Finished in 9 minutes 46 seconds (files took 15.33 seconds to load)
580 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 1612
 Total top-level: 1129
 Total time: 02:28.349 (out of 09:56.659)
 Total uniq factories: 15

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

     439         420       73.7262s            0.1679s            71.8990s               user
     192         108       28.4784s            0.1483s            15.7852s      merge_request
     192         108       11.7917s            0.0614s             6.4906s              issue
     192           0        2.4496s            0.0128s             0.0000s     work_item_type
     126         126        4.5724s            0.0363s             4.5724s          milestone
      84          84        9.1860s            0.1094s             9.1860s      note_on_issue
      84          84       16.4508s            0.1958s            16.4508s note_on_merge_request
      84          84        4.7215s            0.0562s             4.7215s     note_on_commit
      84          84        7.7131s            0.0918s             7.7131s note_on_project_snippet
      84           0        3.8752s            0.0461s             0.0000s    project_snippet
      25          25       10.7602s            0.4304s            10.7602s            project
      11           0        1.0804s            0.0982s             0.0000s          namespace
       7           5        0.9788s            0.1398s             0.7640s              group
       7           0        0.0495s            0.0071s             0.0000s namespace_settings
       1           1        0.0068s            0.0068s             0.0068s            license

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports