Skip to content

Optimize notification_service_spec.rb (expensive setup functions)

Thong Kuah requested to merge notification_service_spec_performance2 into master

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:

Screen_Shot_2020-08-26_at_8.06.01_PM

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

Availability and Testing

Edited by Thong Kuah

Merge request reports