Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Enter the 2020.2 Beta Sweepstakes for a chance to win an Oculus Quest 2.
    Dismiss Notice

Feedback (Case 1211383) Some Editor Overhead in Playmode debunked

Discussion in '2019.3 Beta' started by Peter77, Jan 14, 2020.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
    I believe I made an interesting observation that hopefully helps to solve some of the existing editor overhead performance problems during play mode, which often cause my game to become very laggy and sometimes almost unplayable in the editor (eg this).

    I observed Unity adds a significant processing cost while holding down keys.
    Some key combinations cause the editor performance to drop significantly.
    In a first person shooter you navigate through the world via WASD-keys and SHIFT-key to run, which causes the editor to drop performance significantly, just because of holding these keys.

    The performance drop depends on the window the mouse pointer is located.
    The performance drop is significantly worse while the mouse is over the Hierarchy window than the Game window for example. When testing/playing in the editor, the mouse very often ends up or moves over the hierarchy window.

    1.png

    2.png

    3.png

    I've recorded a rather lengthy video where I go over these findings, which hopefully helps you to solve these performance drop issues.

    Please note that in this test there is no actual game running. It's an empty project. In a real project, you actually have your 30ms (or whatever) spend on the game. If another 30ms kicks in just for editor keystroke processing, this gets unplayable quickly.

    Reproduce
    • Open attached project
    • Open SampleScene
    • Open from main menu "Window > Analysis > Profiler"
    • Switch Profiler to Editor mode and start recording
    • Press Play
    • Hold down "A" key and observe performance in Profiler
    • Hold down "Shift+A" key and observe performance in Profiler
    • Hold down "Shift+A" key while moving the mouse over the Hierarchy and observe performance in Profiler

    Actual
    Holding down keys cause a huge performance drop.

    Expected
    No performance drop.
     
    Last edited: Jan 14, 2020
  2. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    143
    When I was a child my grandfather used to tell me stories about Peter77. He said the common folk called him "QA Jesus" back in the day and that he was feared by all programmers in the west.

    Congrats on yet another detailed performance bug report
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
    QA Jesus, LOL!

    I guess inside Unity Technologies it's more likely they refer to me as "oh no, not him again" ;), even though I have no ill intentions. Really!

    Just kidding, I know Unity staff appreciate my reports, they told me on various occasions.
     
    Last edited: Jan 14, 2020
  4. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    127
    I imagine, at UT, people meeting in kitchen for coffee or something and chatting:

    Nice job Peter!
     
  5. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    143
    Dev's parents:
     
    xVergilx and Bordeaux_Fox like this.
  6. KokkuHub

    KokkuHub

    Joined:
    Feb 15, 2018
    Posts:
    450
    You're not a good QA until developers flinch and recoil when they hear your name.
     
    phobos2077, xVergilx and Peter77 like this.
  7. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,045
    Is this also happening when you hover the inspector window? It might be possible that the performance drop induced by moving the mouse button is the result of highlighting an entry in the hierarchy...
     
    Peter77 likes this.
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
    Holy Moly! They just turned me into QA Jesus for real...
    upload_2020-1-14_18-1-24.png

    Whoever this was: Touché :)
     
  9. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
    The performance impact while holding A, while the mouse pointer is over an empty Inspector window, is the same as when the mouse is over the Game View.

    If there is an object assigned to the Inspector, it shows the same "base cost" for the additional key processing.

    In addition to that, whenever the mouse moves over an UI Inspector element that has a hover state, it triggers a repaint, which is expensive. Perhaps that's also the problem with the Hierarchy.
     
  10. Incode

    Incode

    Joined:
    Apr 5, 2015
    Posts:
    61
    This is possibly the greatest forum thread of all time.
     
    xVergilx, JonSWEDEN and Peter77 like this.
  11. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
  12. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    182
    Amazing :)

    It's the least you deserve for submitting all these reports though...
     
    Peter77 likes this.
  13. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    474
    So everytime I call the Unity Input class, I get these spikes in my game? Is it just in the editor playmode or also in build?
     
  14. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
    No, that shouldn't be the case, or it's at least not what I observed.

    The spikes seem to be related to the editor only.
    I have not seen this in a build.
    The Input API does not seem to play a role in this.
     
  15. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    120
    Woah, this is actually happening. In our project it turns 55 fps to 30!

    The perf impact really varies from key to key, taking as a reference Control and Alt: Enter causes 2x the spike, and Shift actually doesn't cause any.

    Tthe editor still has huge overhead in play mode, even when no input is present and with the GPU almost idling. It even has a "heartbeat". Gonna have to post a ticket.
    editoroverheadreadout.png
     
    Last edited: Jan 21, 2020
  16. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    4,238
    Hi, we are looking into these issues.
    The heartbeat is the profiler window, it only updates every 5 frames for performance reasons.
    Part of the issue in 2019.3 is the profiler window itself, if you hold down A it then shows the timeline view which has a higher perf cost. We are looking into changing this default Key.
    We are also developing an Out Of Process Profiler which will let you capture without the overhead of the profiler itself in the results.

    If you want to compare between versions then the Profile Analyzer is a very good tool to do this https://blogs.unity3d.com/2019/05/13/introducing-the-profile-analyzer/
     
  17. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    325
    That sounds very nice!
     
    joshcamas likes this.
  18. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    120
    In my computer the interval seems to be 67 frames in an empty scene.

    Testing an empty scene just with a FPS counter (not even a camera), EditorLoop still eats 7.5 ms when the only open window is Game. I haven't noticed the profiler making much of a difference, does it always run in the background?

    editoroverheadempty.png

    PS: this is with 2019.3.0f3.
     
    Last edited: Jan 21, 2020
  19. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    4,238
    It could be something else. Just look in the profiler and it will show you what is happening in the spike.

    How much did it use for you in previous unity versions?

    No, it only runs in the background if its enabled via the editor or a script.
     
  20. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    120
    Just more of EditorLoop, 30 ms.

    I'll test later at home with 2018.3.
     
  21. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    120
    Tested it with 2018.3.14f1, there is still EditorLoop there (what does it do that is updated every frame without any input?), but it is only 2.7 ms instead of ~8. It is an inconvenience when testing VR in the editor.

    upload_2020-1-22_3-21-53.png
     
  22. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
    It renders the Editor and generally does what the editor does, which can be a host of things including your own editor scripts, which is why performance should generally be measured in a built player. Now obviously we're talking editor performance here so that's not a solution. To gather more info on what actually happens in the Editor loop, you need to turn on "Profile Editor" (or target Editor instead of Playmode >=2019.3).

    Now in your chart above, you've hidden the "Other" category (or are still on a version where you had to select EditorLoop to actually see it in charts. That's fixed in all latest versions), which in the Editor is mostly comprised of the EditorLoop. So basically we're not able to see Editor spikes in that chart. The Rendering Spike might be cause because the Editor did ask the Render Thread to render something which might've affected rendering times in your PlayerLoop on the main thread, maybe something dragging out from the frame before that, but it's hard to tell like this.

    To reduce EditorLoop overhead, you can also maximize the GameView or close other Editor Windows to reduce Editor related workloads.
     
  23. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
    Btw you can use this little script to turn Editor Profiling on and off via shortcut (the script defaults the shortcut to Shift+E).
    If you want to deep profile, open the Profiler Window, toggle deep profiling on and close the window again, then use the shortcut to profile.

    Once you've captured some data like this, you can load the profiler capture file that this script will place in your Assets Folder into the Profiler Window.
     

    Attached Files:

    valentingurkov and karl_jones like this.
  24. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    120
    Oops, I had others disabled in that picture yes. Using editor profiling the origin of the spikes is solved: it is the profiler being updated.

    Still, in 2019.3.0f3, an empty scene and no windows open (other than Game and Profiler) I'm getting results like this:

    upload_2020-1-23_14-22-41.png

    So 8.61 milliseconds, not counting the profiler updating the graph.
     
  25. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    288
    Hi Peter77, I cannot guarantee a smooth profiling trace with absolutely no spikes and a constant 3-4 ms for each frame, since you know, the editor can do many things in the background, stalling the editor at certain point, i.e. GC, etc., but I can tell you that we have done many investigations since the time you've reported this issue and we'll be able to provide a few improvements here and there that will improve the overall experience.

    As an example, we've speed up the new style drawing code by around 1 ms for 100 iterations which will help in the long run. Also we've revisited many places in the code, where holding a key, causing the OS to fire hundreds of OnGUI.KeyDown events per seconds, was slowing things down without any value. The best optimization is to: not do, what doesn't need to be done.

    As you can see in these two screenshots we now have a gain of 16% for the general case:





    Also using OOPP (available in 20.1) you can see that the GameView perf. was also improved (these improvements will be backported to 19.3 too):





    Finally, we have new tools that will be available in 20.1 (and probably backported for 19.3) to help dig into these performance issues. One of those tool I really like a lot is the Profiler Marker Filtering. The idea is to choose a particular marker, mark it as filtered and then start a trace (i.e. using the performance tracking package). What will happen is that the profiler will only record the scope of the selected marker, discarding all the rest, allowing you to deep profile without all the overhead usually implied with deep profiling enabled and pinning down what you really care about. Here's two videos that show this in action with your sample project:





    I hope things smooth out a bit when these improvements lands, meanwhile keep the fate, we are working hard for you guys!
     
    Last edited: Jan 24, 2020
  26. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    325
    OOPP is already available in a20? How do we use it?
    That's huge!

    Also, great work nailing down those ms. They really add up and I know we've all lost countless hours due to them.
    The editor perf improvements are my favorite part of the release notes and I'm always looking forward to seeing more and more of them. Many of us are, for sure.
     
  27. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    985
    What is OOPP?

    I like the idea of profile markers, that's gonna help a lot
     
    Peter77 likes this.
  28. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
    OOPP stands for Out-of-process Profiler, the internal name for the Standalone Profiler that ships with 2020.1.0a21

    in 2020.1.0a21 you'll find it right underneath the Profiler entry as Window>Analysis>Profiler (Standalone Process). It'll spin up another Editor Process to contain the Profiler Window and related windows.
     
    SugoiDev, CDF, jonathans42 and 2 others like this.
  29. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
    Thank you and the team for not taking the bug-report lightly. I'm looking forward to an update where I can test the improvements.
     
    LeonhardP and konsic like this.
  30. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,243
    It looks like we found the cause for the random spikes. We have a fix in review and will hopefully be able to share it with you soon.
     
    MechEthan, konsic, HB_AlexSz and 2 others like this.
  31. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
    Excellent news, Leonhard. Thanks for the update!
     
    LeonhardP likes this.
  32. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    288
    This issue has been fixed and will be available in the next release of >=2020.1.0a24. The fix will eventually backported to 2019.3 when we are sure it is stable enough.
     
    Last edited: Feb 13, 2020
  33. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    100
    When reading the first post it looks like a similar problem I reported (1249910), but if it really was fixed, then it probably wasn't. The editor lags/buffers input (while playing or not) if a keyboard button is pressed and the mouse moves. The lag can grow to several seconds and can easily be reproduced by:
    - Create a new empty project, and set vsync to 30 fps (only needed for beefy computers).
    - Create a script that does something while a key is pressed. For example:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class MoveIfPressed : MonoBehaviour {
    4.     public KeyCode key = KeyCode.Space;
    5.     void Update() {
    6.         if (Input.GetKey(key)) transform.position = Random.onUnitSphere;
    7.     }
    8. }
    - Add the script to a cube, point a camera to it.
    - Have both the Scene View and the Game View opened. Open the profiler and set it to record mode. Hit play.
    - Now keep the key pressed and move the mouse around on the game window. After some seconds, release the key.

    The cube should keep moving after the key is released.

    This problem seems to happen if the scene view and game view are opened and some window, like the profiler, is doing something, but I had this problem even with the game view maximized (but now I can't reproduce it).
     
  34. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    345
    @jonathans42
    I'm seeing this issue still happening in the recently released Unity 2019.4 LTS...
     
    JamesArndt likes this.
  35. VictorShubin

    VictorShubin

    Joined:
    Jan 20, 2020
    Posts:
    2
    OMG! Dude, Thank you! This is exactly what I was experiencing! I hope they do something about it or at least release a statement.
    I also wanted to add that this "bug" or whatever especially hits performance when my laptop in powersaving mode (I think it's downthrottling under light loads and then FPS drops to like 15 when you hold keys) this issue however goes away when I start to watch some videos in the background (maybe laptop throttles back up). Really strange behavior.
     
  36. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,215
    I believe part of their fix is the new "Interaction Mode". Once I set this from "No Throttling" to "Monitor Refresh Rate", everything is faster. However, I'm not sure if that exists in 2019.4, I believe it's available in 2020.1 and newer only.

    upload_2020-7-9_13-22-28.png
     
  37. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,139
    2019.4 has it too.
    Screenshot 2020-07-09 at 2.28.19 PM.png
     
    Peter77 likes this.
  38. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
    Yes, it's that plus additional fixes to how input is handled that either already shipped, landed or are in flight for all versions back to 2019.4. So, give it a few versions for the dust to settle and this should be solved. If not, please don't hesitate to file new bug reports on this when it's still present in some form on the latest versions in a month or so.
     
    Peter77 and karl_jones like this.
unityunity