Search Unity

Particle System profiling: What is ParticleSystem.WaitForPreviousRenderingToFinish ?

Discussion in 'General Graphics' started by fastgamedev, Jul 15, 2018.

  1. fastgamedev

    fastgamedev

    Joined:
    Mar 27, 2014
    Posts:
    91
    I am profiling a scene where particle systems are generating spikes of cpu activity. (See screenshot.) This shouldn't be happening, - there are only a handful of basic particles.

    Profiler says it's due to ParticleSystem.WaitForPreviousRenderingToFinish. What is it and how to optimize it?
     

    Attached Files:

  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    4,421
    You should not profile the game running inside the editor. Create a build and profile it on the target platform instead. A build and the editor often have significantly different performance- and memory allocation characteristics. Many systems in Unity run significantly faster in a build.



     
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    The particle update for the current frame cannot begin until the render thread has finished submitting the draw calls for the previous cpu frame.

    It’s a bottleneck that we are working on removing.

    Maybe better batching/fewer draw calls can help you optimise it in the current versions of Unity.
     
    konsic likes this.
  4. uwustudio

    uwustudio

    Joined:
    Jun 22, 2017
    Posts:
    2
    We noticed the same problem which basically breaks our game when using the Deferred rendering path.
    However we don't have this problem when using the Forward rendering path.

    Is there any ETA for this fix?
     
  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    We are working on it for 2018.3, with possible backport to 2018.2.
     
    Malveka likes this.
  6. Malveka

    Malveka

    Joined:
    Nov 6, 2009
    Posts:
    175
    Also seeing this. A fix would be welcome, especially if it could be in 2018.2 within the next 3 weeks! :)

    wait_for_previous_rendering.JPG
     
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    To be honest I think it’s unlikely it will be ready that soon, sorry!
     
    Malveka likes this.
  8. Malveka

    Malveka

    Joined:
    Nov 6, 2009
    Posts:
    175
    Hey Richard, thanks for the reply! I've done some more digging and, while ParticleSystem.WaitForPreviousRenderingToFinish may be an issue of some kind, it does not seem to be the actual source of my performance issue. From what I can make out so far, I've got a compute shader that is consuming a lot of cycles.

    I noticed that if I turned off the Renderer for each of my particle systems in the scene, ParticleSystem.WaitForPreviousRenderingToFinish disappeared from the profile trace, but my frame rate didn't change.
     
    richardkettlewell likes this.
  9. WaaghMan

    WaaghMan

    Joined:
    Jan 27, 2014
    Posts:
    214
    Chiming in to say this is a high priority issue. Even a simple query to particleSystem.isPlaying on a Stopped ParticleSystem! will cause the Update() to stall if the renderer thread is still processing the previous frame (which will cause the next frame to lag behind as well, of course...).
     
  10. MichiealO

    MichiealO

    Joined:
    Jul 7, 2013
    Posts:
    61
    I'd like to chime in and say that I would also like to see a fix for this. This issue is causing me all kinds of stress.
     
  11. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    Doing my head in. Please. Yes. This. Fix!

    I'm seeing this when adding bursts via script.
     
  12. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    This is a good point worth raising, because it's a simple bug, for which I've just made a fix. Thanks for raising it.
    The script should only "wait for rendering" if the particle array is modified, via Emit or SetParticles calls. The following methods could have caused an unnecessary stall:

    - GetParticles
    - isPlaying
    - isEmitting
    - isStopped
    - isPaused
    - particleCount
    - time
    - randomSeed
    - useAutoRandomSeed

    That said, we are still working on the root problem, to remove all cases where the stall could happen.
     
    Peter77 and Deeeds like this.
  13. WaaghMan

    WaaghMan

    Joined:
    Jan 27, 2014
    Posts:
    214
    Glad to be of help :) I think in our case that should be enough to fix the performance issue, as we rarely modify particle system properties or manually spawn them, we just were checking if the particle system had finished (isPlaying==false, particleCount == 0) and disable their gameobject when this happens.
     
    richardkettlewell likes this.
  14. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    Hi everyone,

    We (finally) have another update on this. Thanks for your patience.
    The work has been completed and will be available in 2018.3. The first version it will be available in is 2018.3.0b7.

    Due to the scope of the fix, we do not believe it is safe to backport to 2017.4 or 2018.2, as it could introduce other unwanted side effects. We have time to fix these kinds of issues during the 2018 beta cycle, but cannot risk shipping to our stable 2017 release cycle, in case it causes other issues. Apologies that this fix will only be available in the 2018 cycle.

    To be clear:
    The fix is in 2018.3
    The fix is not in 2017.4 or 2018.2
     
    Last edited: Oct 31, 2018
    karl_jones likes this.
  15. laurentHINS

    laurentHINS

    Joined:
    Jun 6, 2017
    Posts:
    2
    Hi Richard, Thanks for fixing this issue. But are you sure about your last statement ? (The fix is in 2018.3 or 2018.2)
    I'm running 2018.2 and the fix is not there cause I still have the same issue. You are saying at the beginning of your post that : "Due to the scope of the fix, we do not believe it is safe to backport to 2017.4 or 2018.2, as it could introduce other unwanted side effects."
    Please, could you confirm ?
    Also could you tell me if Unity 2018 is in fact (at the current date) still in beta?
    And if yes, why are you shipping this version when I just click the download Unity button on your website?
     
  16. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    Sorry, a copy-paste mistake! I have fixed my earlier post. I hope it is clear for you now.
     
  17. joaobsneto

    joaobsneto

    Joined:
    Dec 10, 2009
    Posts:
    146
    I'm having this problem in Unity 2018.3.12f1, or it is something else?
    particlesystem.png
     
  18. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    Can you submit a bug report?
     
  19. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    40
    I am still getting this on 2018.3.12f1 as well, any update?
     
  20. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    4,421
    You can try to update to the latest 2018.4 version:
    https://unity3d.com/get-unity/download/archive

    If the issue still persists in 2018.4, it would probably help @richardkettlewell if you could submit a bug-report as described in this document, so he can take a look at the issue:
    https://unity3d.com/unity/qa/bug-reporting

    It's important that you report these issues together with a reproduction project if you want them to get fixed. If you don't do it, it might be a long time until someone else reports them or until Unity Technologies find them.

    After you submitted the bug-report, you receive a confirmation email with a bug-report Case number. I would t hen post the Case number (number only, not the link) in this forum thread for Richard to pick up.
     
    richardkettlewell likes this.
  21. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    40
    Well, I just re-read this bit from Richard a few posts back and realised that I was calling Emit and/or SetParticles, so in my case I think the behaviour is as expected.
     
  22. Nikodemus

    Nikodemus

    Joined:
    Nov 28, 2014
    Posts:
    20
    Is this fix in the beta 3 2019.2? Getting abnormal spikes on the Oculus Quest.
     
  23. xzbobzx

    xzbobzx

    Joined:
    Apr 7, 2015
    Posts:
    27
    So what version of Unity has this fixed (if any)? I'm getting heavy spikes on 2018.3.0f2

    (with profiler connected to build)

     
  24. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    4,421
  25. Nikodemus

    Nikodemus

    Joined:
    Nov 28, 2014
    Posts:
    20
    Same issue with 2018.4.1.
     
  26. mrtenda

    mrtenda

    Joined:
    Jun 6, 2017
    Posts:
    31
    Did this fix make it into 2019.2? I'm still seeing it consistently happen in 2019.2.5f1:

    upload_2019-9-12_6-1-56.png
     
  27. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    Yes. What are the threads doing on the timeline profiler view?
     
  28. mrtenda

    mrtenda

    Joined:
    Jun 6, 2017
    Posts:
    31
    Here's what the profiler window looks like with the CPU spike selected:

    upload_2019-9-12_7-32-2.png
     
  29. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    The job threads are collapsed but I think I can see 2 very long-running particle jobs in there. Those would cause the stall. Are you sure you haven’t got some very expensive particle systems in your scene?

    Eg very high particle counts, or mesh particles that aren’t using gpu instancing, would be the 2 most likely candidates.
     
    chLim and mrtenda like this.
  30. mrtenda

    mrtenda

    Joined:
    Jun 6, 2017
    Posts:
    31
    Whoops, looks like it was just a high particle count as you mentioned. Sorry, I should have looked into that first. Thanks for the help!
     
    richardkettlewell likes this.
  31. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,282
    Glad you sorted it!
     
    mrtenda likes this.
unityunity