Search Unity

What is StackTraceUtility?

Discussion in 'General Discussion' started by galatim, Mar 23, 2023.

  1. galatim

    galatim

    Joined:
    Feb 28, 2023
    Posts:
    3
    https://imgur.com/a/Vc1o7S7
    As you can see, StackTraceUtility.ExtractStringFromExceptionInternal is taking so long time in my development build in Android device.

    My question is what is StackTraceUtility, and will it costy in release build?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,569
     
  3. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,698
    This is followed right away by "LogStringToConsole". You probably have (uncaught) exceptions occurring and the time is spent on those (regularly occurring exceptions (despite being caught), should better be avoided in C#).
    Also saying just in case: Don't use Debug.log() in the Update method (like printing every single frame). That can even deteriorate performance on desktops and Unity does not remove them in release builds because it can still be meaningful to log from builds (log is saved somewhere in %appdata% on desktops).
     
    Last edited: Mar 23, 2023
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,569
    LogStringToConsole takes 0.5 seconds, while StackTrace takes 11.

    All of that happens within Self while the function is called only 27 times.
     
  5. galatim

    galatim

    Joined:
    Feb 28, 2023
    Posts:
    3
    Nice way, I will try ChatGPT by myself
     
  6. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    It's the thing which generates stack traces, i.e. prints the hierarchy of calls in log messages and errors.

    It's expensive, but shouldn't matter for performance as you shouldn't be logging stuff often, and you shouldn't be hitting errors or exceptions, ideally, at all.

    Also, in a release build it doesn't fully track this stuff anyway.