Optimize notification_service_spec.rb (expensive setup functions)
What does this MR do?
Related issues: #241148, https://gitlab.com/gitlab-org/plan/-/issues/145
Call some expensive function once at start of suite
Rather than calling the function before every example, we use before_all
to call the function only once (per suite).
This functions are expensive because they add multiple users, corresponding project member DB records and also generate new team member emails:
- build_team
- build_group
- add_users
Queries saved: 189616
Before:
Total events: 325847
After:
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 02:32.351 of 12:13.808 (20.76%)
Total events: 136231
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 02:32.351 (136231 / 322) of 12:13.808 (20.76%)
Finished in 12 minutes 17 seconds (files took 5.13 seconds to load)
Screenshots
Found with flamegraph:
TEST_STACK_PROF_INTERVAL=3000 TEST_STACK_PROF=1 ss -f d spec/services/notification_service_spec.rb -e 'participating notifications'
# As the resultant dump (115M) is too big for `stackprof --flamegraph` to process, we use speedscope.app instead
ruby -e "require 'json'; puts JSON.generate(Marshal.load(File.binread('tmp/test_prof/stack-prof-report-wall-raw-total.dump')))" > profile-for-speedscope.json
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process.
Edited by Thong Kuah