Profiler. Overhead for first time invocation of functions?

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?

1 Like
1 Like

@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.

3 Likes

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

3 Likes