Skip to content

Improve performance of search project service spec

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

What does this MR do?

This MR improves performance for search project 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/project_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 !78333 (merged).

RSpec Profiling

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

  • Total amount of factories created went down from 4115 to 1571 🚀
  • Total events went down from 170667 to 80086
  • Queries saved: 88137

Before

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 06:35.416 of 21:14.181 (31.03%)
Total events: 170667

Top 5 slowest suites (by time):

Search::ProjectService (./ee/spec/services/search/project_service_spec.rb:5) – 06:35.416 (170667 / 633) of 21:14.181 (31.03%)



Finished in 21 minutes 30 seconds (files took 19.96 seconds to load)
633 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 4115
 Total top-level: 2380
 Total time: 12:33.110 (out of 21:44.506)
 Total uniq factories: 15

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

    1238        1238      599.0958s            0.4839s           599.0958s            project
    1028         410      177.8534s            0.1730s            67.3043s               user
     620           0      106.7461s            0.1722s             0.0000s          namespace
     192         108       35.4543s            0.1847s            19.8790s      merge_request
     192         108       13.5569s            0.0706s             7.0003s              issue
     192           0        3.2701s            0.0170s             0.0000s     work_item_type
     126         126        4.3059s            0.0342s             4.3059s          milestone
      84          84       12.1302s            0.1444s            12.1302s      note_on_issue
      84          84       20.4733s            0.2437s            20.4733s note_on_merge_request
      84          84        6.9925s            0.0832s             6.9925s     note_on_commit
      84          84        9.8760s            0.1176s             9.8760s note_on_project_snippet
      84           0        4.7959s            0.0571s             0.0000s    project_snippet
      53          53        6.0440s            0.1140s             6.0440s              group
      53           0        0.4734s            0.0089s             0.0000s namespace_settings
       1           1        0.0089s            0.0089s             0.0089s            license

After

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 02:07.990 of 10:41.631 (19.95%)
Total events: 80086

Top 5 slowest suites (by time):

Search::ProjectService (./ee/spec/services/search/project_service_spec.rb:5) – 02:07.990 (80086 / 633) of 10:41.631 (19.95%)



Finished in 10 minutes 51 seconds (files took 15.01 seconds to load)
633 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 1571
 Total top-level: 1108
 Total time: 02:18.310 (out of 11:01.416)
 Total uniq factories: 15

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

     416         410       66.9369s            0.1609s            66.5944s               user
     192         108       28.3700s            0.1478s            15.5088s      merge_request
     192         108       11.5928s            0.0604s             6.2264s              issue
     192           0        2.4029s            0.0125s             0.0000s     work_item_type
     126         126        4.3847s            0.0348s             4.3847s          milestone
      84          84        9.2320s            0.1099s             9.2320s      note_on_issue
      84          84       16.5629s            0.1972s            16.5629s note_on_merge_request
      84          84        4.8220s            0.0574s             4.8220s     note_on_commit
      84          84        7.3126s            0.0871s             7.3126s note_on_project_snippet
      84           0        3.6326s            0.0432s             0.0000s    project_snippet
      17          17        7.5164s            0.4421s             7.5164s            project
      11           0        1.1611s            0.1056s             0.0000s          namespace
       2           2        0.1436s            0.0718s             0.1436s              group
       2           0        0.0161s            0.0081s             0.0000s namespace_settings
       1           1        0.0064s            0.0064s             0.0064s            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