Search Unity

Profiler. Overhead for first time invocation of functions?

Discussion in 'Scripting' started by jamie_dubit, May 13, 2019.

  1. jamie_dubit

    jamie_dubit

    Joined:
    Jan 8, 2015
    Posts:
    5
    Hello.

    I am profiling our game, and have noticed that for certain events in our game the profiler is showing a heavy cost for the first time it happens, and less so on subsequent calls.

    My initial reaction was along the lines of "oh there must be some caching being done at engline level" but after looking at the deep profile hierarchy, there seems to be extra cost associated with every one of my functions in the call stack, not just engine level stuff. The first time there is a lot more "Self" time in the functions, and every funtion just seems heavier. in one situation it's more than 5 x more.

    My suspicion is that it's something to do with the profiler, having to initialize itself to measure those functions for the first time. I can't find any info on this in the documentation. Can anybody confirm my suspicions?
     
    IgorAherne likes this.
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
  3. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    508
    @palex-nx is right - in the Editor (and Players with non-AOT Mono scripting backend) the first function call initiates JIT compilation.
    We've added recently (2019.1) Mono.JIT profiler marker to highlight this.
     
    daoth90, IgorAherne and MartinTilo like this.
  4. jamie_dubit

    jamie_dubit

    Joined:
    Jan 8, 2015
    Posts:
    5
    I had suspicion about JIT but it I know won't affect IL2CPP. It didn't click in my head that editor is on mono. Makes sense. Thanks