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

How to interpret impossible recursion in Profiler hierarchy?

Discussion in 'Editor & General Support' started by JoeStrout, May 15, 2019.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I've got a project here that, when I do a Deep Profile, shows some really strange results in the profiler.

    upload_2019-5-15_6-57-33.png

    Looks like GetGlobalValue calls itself... a number of times... which then calls Update, which calls itself at least once, and so on in a merry recursion of impossible steps.

    I say impossible because none only the top few steps there look like anything that could actually happen in the code. For example, the code of GetGlobalValue is:

    Code (CSharp):
    1.         public Value GetGlobalValue(string varName) {
    2.             if (UnityEngine.Random.Range(0,10000) == 42) {
    3.                 UnityEngine.Debug.LogWarning("Really recursing?!?");
    4.             }
    5.             if (vm == null) return null;
    6.             TAC.Context c = vm.globalContext;
    7.             if (c == null) return null;
    8.             try {
    9.                 return c.GetVar(varName);
    10.             } catch (UndefinedIdentifierException) {
    11.                 return null;
    12.             }
    13.         }
    14.  
    The only call in this is GetVar, which does not appear in the profile, and shouldn't be invoking GetGlobalValue in any case. Moreover, I added that Debug.LogWarning above, so that now and then GetGlobalValue logs a message and I can examine the call stack thereof. If the shenanigans claimed by the profiler were actually happening, most of the GetGlobalValue logs should have a deep call stack. But instead, the results all look like this:

    upload_2019-5-15_7-1-36.png

    So it looks to me like the profiler's just confused. But I've run very similar code in other projects without any such confusion. Anybody have any idea what could cause this sort of thing, and how I can make it stop? I'd really like an accurate profile so I can focus optimization efforts on the right things.
     
  2. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    Hi,

    Thanks for posting the issue!

    Which version of Unity do you see such behavior?
    The way deep profiler works is injecting begin/end pair on function enter exit. However when exception happens the end call is not happening. And I think this might be the case here. With old scripting runtime there was no way AFAIK to intercept exception withing a specific method and compensate for this missing end. With new scripting runtime we do intercept exceptions and inject end sample.
    If you see such behavior in a new scripting runtime this is a bug. Could you please then create a bugreport and post it in this thread, so I can followup later.
     
    MartinTilo likes this.