Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Severe lag in both Editor and Player when moving mouse after several hours

Discussion in 'Editor & General Support' started by Fantabulosoful, Nov 27, 2019.

  1. Fantabulosoful

    Fantabulosoful

    Joined:
    Dec 24, 2012
    Posts:
    2
    Hello!

    I've been encountering a bizarre, memory-leak-esque issue in my project since mid-august, and was hoping to find some support for it here, as the issue has persisted across every version of the 2019.2 release cycle I've tried (19.2.3 through 19.2.13), and through multiple re-installs and attempted fixes. I was hoping that a Unity update would squash this issue, or I'd be able to solve it myself, but it's seeming like neither of those are happening anytime soon - I've put a tl;dr summary down at the bottom, but I want to address as many potential questions as I can right here.

    Long story short, after a seemingly random amount of time (usually around 2-4 hours) both in-editor and in-player, Unity begins undergoing massive amounts of lag - but only when the mouse is moving. Other forms of camera movement, either via an animation or use of a controller, have no effect on the framerate, and by profiling the editor I can see it occurs even when not in play mode. The frame drops are very severe, and worsen over time; on my system, the Player runs at a consistent 100+ fps, and when the issue begins to manifest drops to sub-20 upon moving the mouse. Restarting Unity fixes the issue both in Player and in Editor - "just restart when it lags" isn't really a good thing for players to need to adhere to, though!

    When analyzing the frames where this lag occurs via the profiler, there's a massive amount of CPU time spent in the "Others" category which seems to be assigned directly to EditorLoop. When I go through and select them, none of its children illuminate themselves to make up for the massive spikes it contains, their % of CPU time are only a fraction (usually less than 30%) of the 100% total. I've attached a picture of this here:



    All the spiking behavior you see above is from me moving the mouse, while the flat periods are how the editor runs normally. The speed of movement doesn't seem to matter, with the only factor being whether or not new mouse input is being read. Lastly, though the above image is not in play mode, this spiking behavior only manifests in the EditorLoop portion of the hierarchy, even when in play mode.

    The only potential culprits I've found are two of the functions in the hierarchy above: LargeAllocation.Free and LargeAllocation.Alloc. Though they come nowhere near the massive amount of CPU time spent on these frames, they only ever show up on frames where the mouse is moving.

    Something even more baffling is that I'm apparently the only one to have ever witnessed these functions - a google search for either of the exact phrases brings up only one result, a thread I made on Reddit a little under a month ago. Considering that, it's natural that there are no results in Unity's documentation for this issue, and I haven't found anyone else who has encountered it.

    I've tried everything I can think of to fix the lag, from updating/reinstalling Unity, to using the Memory Profiler to hunt down a memory leak, to deleting every single asset in my project to isolate the culprit (with a backup!). Even with absolutely no assets in the project, the lag persisted in the editor until I restarted Unity.

    The issue does potentially seem to be accelerated by playing in-player and working in the editor. Leaving it open overnight often doesn't result in the issue occurring, but working for a two hour session has caused it to happen twice today alone. I've attempted to analyze a fresh project as well: the issue doesn't seem happen in a brand-new, empty project, but that may simply be from me not waiting long enough for it to occur

    I doubt a third-party asset or package could be causing this, due to the fact that the issue persisted even after deleting every single asset from the project (and removing non-default packages), but I am using a fair number of utility assets. I likely missed a couple, but most prominently, these are:
    • Amplify Shader Editor (what I've been working with today)
    • Rewired Input
    • Easy Save
    • Easy Decal
    • AStar Pathfinding
    Additionally, I have the following packages installed at the time of the above Profiler screenshot:



    Finally, I'm unsure what file host would be best (or even allowed here), but I'd be happy to upload the saved Profiler data from the image above. It's approximately 60 megabytes, however, so I can't attach it directly to this post.

    TL;DR: My project has been suffering from severe lag when moving the mouse, both in-editor and in-player, for approximately 3 months and across multiple Unity installs. The lag only occurs after at least an hour since the player/editor was started. This behavior persists even when all assets are deleted, and is seemingly tied to two mystery functions in the Profiler, LargeAllocation.Alloc and LargeAllocation.Free. Does anybody have any ideas what this could be?
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,432
    Hi :)
    from what you're describing the issue seems to be with a script that operates in EditMode, like an editor extension or your use of it and it may create and free large allocations, such as those of Assets. As such, from the list you've shown, Easy Save sounds like a good first candidate to take a closer look at. you could put ProfilerMarkers around any likely critical calls to mark them up in the Profiler or use Deep Profiling together with Editor Profiling (no need to have the player running too I guess.

    It being linked to the mouse moving might mean that it happens in any EditorUpdate/Repaint of some Window or in Mouse events.
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,432
    You might also want to trigger profiling to a file on pressing of a certain key or menu item to avoid capturing the profiler Window while you profile.