Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Editor - CPU spikes in editor, makes game and editor freeze

Discussion in 'Editor & General Support' started by NTDC-DEV, Feb 11, 2011.

  1. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    Hi,

    Since my update to 3.2 I've been experiencing weird CPU spikes. I first saw the spikes in-game....

    I thought my in-game scripts were faulty so I checked the profiler and slowly deactivated all running scripts. But whatever I deactivated, another script took the cpu overhead crown in the spikes... so something started to smell fishy.

    I closed my unity editor, reloaded it. All was fine until I ran the game again. The spikes came back. And with each spike there is a freeze... So something in my in-game scripts is causing a memory leak ? Following that idea, the GC is probably trying to fix/grab it but can't and voila! Spikes?

    Without running the game, just moving a window (any window) in unity I could see my CPU spike in the task manager and the moving window freeze for a moment during the said spike.

    Running Win7 64bit (with that hotfix)
    i7 950 CPU (doubt my machine is in fault, and anyhow it started happening after I upgraded to 3.2)
    Restarted unity/computer half a dozen times already....

    If anyone is experiencing this issue please feel free to add to this topic.
    Thanks!

    Update:
    Wow, I found the problem... a yield in a while statement in an update of one of my scripts was somehow pumping calls and messing up the GC. Why didn't that happen in 3.1? No idea. Why was the GC still trying unsucessfully once the game was stopped? No idea either.

    Oh well... all is back to normal.


    Update2:
    Nevermind still doing the bug.
     
    Last edited: Feb 17, 2011
  2. mindengine

    mindengine

    Joined:
    Sep 8, 2008
    Posts:
    114
    Experiencing similar IDE slow down when running my game. I am on a mac dual core.

    I rolled back to 3.1 and all is fine again.
     
  3. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    New update: Well, it helped a bit to remove those lines of code but the spikes came back. Maybe I had a mix of problems or maybe they had nothing to do and only accentuated the real problem which is still a mystery.
     
  4. KevS

    KevS

    Joined:
    Apr 21, 2010
    Posts:
    51
  5. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    The spikes seem to have stopped... and yes it seems it is the GC / OnGUI combo.

    I had some nasty code that was actually calling more than 1 OnGUI. I centralized the code inside 1 OnGUI and the spikes stopped.

    Basically, the profiler was sending me to the Physics.Simulate culprit but (and I'm guessing here) because the GC has priority it just monopolizes the Update(), thus the change to the next frame... which meanwhile the FixedUpdate() on which physics run, continues to run and accumulates calls/processes until the GC finishes? The profiler shows that accumulation as being a spike... Is there any way to tell the profiler to show differently Updates vs FixedUpdates?

    And all of that doesn't explain why the editor stutters even when the game isn't running... Memory leak?
    And it also doesn't explain why I didn't had that bug in 3.1 vs 3.2... Something still smells fishy here...

    Oh well.. I HOPE it won't come back now.
     
    Last edited: Feb 14, 2011
  6. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    IT CAME BACK.

    For the sake of clarity in this whole story I'll add a final reply... before this get fixed by the Unity team (if it does).

    After a lot of time spent/lost searching for problems in my code I decided to give up. Please, for those who are experiencing it too, file a bug report if it hasn't been done already. (I just can't do it, don't have internet on my workstation... Suggestion: Add a non-editor bug reporting other than sending email?)

    The ONLY 100% solution I found is to actually de-activate ALL my GO's in my project and re-activate them. The editor then works flawlessly and so the game. I have over 3000 GO's, going one by one and searching would be hell, so no I won't do it, at least not right now.

    I'm guessing something broke during the conversion from 3.1 to 3.2 as this was not present in 3.1.
     
  7. Belchlord

    Belchlord

    Joined:
    Mar 13, 2011
    Posts:
    4
    Okay so I got the exact same problem on my windows system.

    When I do a standalone build, it doesnt seem to happen.

    Im executing the same code on 2 macs and neither of them have the problem. Sometimes after a lot of use, it just goes away for a while, if I reboot it comes back.

    Im stumpted.

    Using 3.3