Skip to content

Improve performance of search global service spec

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

What does this MR do?

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

Note that the performance improvement is not as significant as in !78333 (merged) and !78334 (merged) but still notable.

RSpec Profiling

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

  • Total amount of factories created went down from 2532 to 1323 🚀
  • Total events went down from 104311 to 68061
  • Queries saved: 36250

Before

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 03:33.059 of 12:37.201 (28.14%)
Total events: 104311

Top 5 slowest suites (by time):

Search::GlobalService (./ee/spec/services/search/global_service_spec.rb:5) – 03:33.059 (104311 / 650) of 12:37.201 (28.14%)



Finished in 12 minutes 51 seconds (files took 16.29 seconds to load)
650 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 2532
 Total top-level: 1691
 Total time: 06:12.325 (out of 13:02.814)
 Total uniq factories: 18

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

    1030         513      158.8747s            0.1542s            75.3771s               user
     586         586      240.9107s            0.4111s           240.9107s            project
     157         115       26.7324s            0.1703s            19.5025s      merge_request
     127          85        7.6388s            0.0601s             4.8972s              issue
     127           0        1.9030s            0.0150s             0.0000s     work_item_type
     126         126        4.3724s            0.0347s             4.3724s          milestone
      87          87        5.1087s            0.0587s             5.1087s               note
      69           0       11.5139s            0.1669s             0.0000s          namespace
      42          42        5.0645s            0.1206s             5.0645s      note_on_issue
      42          42        9.4629s            0.2253s             9.4629s note_on_merge_request
      42          42        2.6852s            0.0639s             2.6852s     note_on_commit
      42          42        4.5957s            0.1094s             4.5957s note_on_project_snippet
      42           0        2.2559s            0.0537s             0.0000s    project_snippet
       7           7        0.0392s            0.0056s             0.0392s             commit
       2           2        0.2389s            0.1195s             0.2389s              group
       2           0        0.0111s            0.0055s             0.0000s namespace_settings
       1           1        0.0106s            0.0106s             0.0106s            license
       1           1        0.0596s            0.0596s             0.0596s              admin

After

[TEST PROF INFO] EventProf results for sql.active_record

Total time: 02:27.455 of 11:04.473 (22.19%)
Total events: 68061

Top 5 slowest suites (by time):

Search::GlobalService (./ee/spec/services/search/global_service_spec.rb:5) – 02:27.455 (68061 / 650) of 11:04.473 (22.19%)



Finished in 12 minutes 1 second (files took 20.19 seconds to load)
650 examples, 0 failures

[TEST PROF INFO] Factories usage

 Total: 1323
 Total top-level: 1059
 Total time: 02:44.342 (out of 12:15.482)
 Total uniq factories: 18

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

     462         458       93.7395s            0.2029s            93.4462s               user
     157         115       32.9961s            0.2102s            23.7801s      merge_request
     127          85       10.2377s            0.0806s             6.5390s              issue
     127           0        2.1284s            0.0168s             0.0000s     work_item_type
     126         126        5.4509s            0.0433s             5.4509s          milestone
      87          87        5.2322s            0.0601s             5.2322s               note
      42          42        6.3714s            0.1517s             6.3714s      note_on_issue
      42          42       11.8171s            0.2814s            11.8171s note_on_merge_request
      42          42        3.4159s            0.0813s             3.4159s     note_on_commit
      42          42        5.1113s            0.1217s             5.1113s note_on_project_snippet
      42           0        2.4266s            0.0578s             0.0000s    project_snippet
       9           9        2.8016s            0.3113s             2.8016s            project
       7           7        0.0449s            0.0064s             0.0449s             commit
       5           0        0.4411s            0.0882s             0.0000s          namespace
       2           2        0.2550s            0.1275s             0.2550s              group
       2           0        0.0128s            0.0064s             0.0000s namespace_settings
       1           1        0.0211s            0.0211s             0.0211s            license
       1           1        0.0557s            0.0557s             0.0557s              admin

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