I am loading my game scene by calling SceneManager.LoadScene. However, I am occasionally getting long load times when loading a game scene in my builds. I have not been able to reproduce this consistently, but while debugging this issue, I noticed that I can reproduce this problem every time in the Unity Editor (2017.3) on the first play.
If I enter play mode for the first time after the Unity Editor is launched and then click an in-game button to load my game scene, the profiler shows that Application.WaitForAsyncOperationToComplete is taking ~9000 ms. I am having trouble debugging it because the time is spent in "Self ms".
If I re-enter play mode and repeat the same steps, subsequent runs show that WaitForAsyncOperationToComplete only takes ~200 ms. The time jumps back up to 9000 ms if I re-open the Unity Editor and repeat the same steps.
How can I debug and fix this long "Self ms" time in WaitForAsyncOperationToComplete? I am also wondering what could be causing this long delay only on the first play after opening the Unity Editor (and what persists in the Unity editor between play mode runs).
My profiler hierarchy looks like this:
EarlyUpdate.UpdatePreloading
- Loading.UpdatePreloading
-- UpdatePreloading
--- Application.WaitForAsyncOperationToComplete [*takes about 9000 ms, 8500 self ms*]
---- PreloadSingleStep [*takes about 500 ms*]
----- Application.LoadLevelAsync Integrate
----- Loading.AwakeFromLoad
----- (...)
See below for a screenshot of the profiler on the first play after Unity Editor is launched (note that Deep Profile is off, but the result is similar with Deep Profile on):
See below for a screenshot of profiler on subsequent playthroughs (and note that "Self ms" is down to a more reasonable ~200 ms rather than ~9000 ms):

