Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Debug.Log statements and code performance

Discussion in 'Scripting' started by eco_bach, May 30, 2018.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Something I've wondered, do Debug statements have any impact on code performance for compiled apps? Lets say for some reason you've kept Debug.Log statements in all your Update loops.
    Does your compiled code run slower as a result?
     
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    777
    I'm interested of this too, and also if the checkbox for "Development build" in Build Settings will turn of all Debug.Log completely when disabled.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,196
    Debug.Log is one of the most expensive single operations you can do in Unity. By default, it includes a complete stack trace of all your code, which requires stopping all executing, walking from where you call Debug.Log from and back through all method calls that got the flow there.

    Having a few Debug.Log calls per frame will definitely cause a noticeable performance degradation.

    As a general rule, remove all Debug.Logs once you don't need them anymore. It's a tool for quick debugging during development, and should not be used as a logging tool. If you need to output information because something's gone wrong, use LogWarning and LogError instead, and try to remove the causes of those logs when you find them.
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,444
    https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity7.html

    https://unity3d.com/learn/tutorials...ion/optimizing-garbage-collection-unity-games
     
    PutridEx, IgorAherne and arfish like this.
  5. visca_c

    visca_c

    Joined:
    Apr 7, 2014
    Posts:
    27
    Do Debug.Log run in non-development builds as well? I was under the impression they are automatically removed when you make a non-development build like other editor-only functions.
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,444
    visca_c likes this.