How to compile function? (to prevent JIT spikes)

Hello there.

I have a game that’s almost ready and it’s stuttering on low-end Android devices due to JIT spikes. Whenever I call a function for the first time the game stutters but it runs smoothly on the subsequent calls.

It seems RuntimeHelper.PrepareMethod is not available in Unity and I’d like to know if there’s a way to somehow compile the functions without calling them.

I’m 100% sure that the problem is the JIT compilation, not only because of the obvious symptoms but also I asked a friend to profile the scripts in a low-end Android device and he confirmed the problem is that.

Any help is appreciated.

Hello guys,

I don’t know if I can answer myself, but found a way to compile a function without running it, just call:


I can confirm this works flawlessly.

Functions called in the function being compiled won’t be compiled because you’re not actually running it, so if you have a functionA that just calls functionB (which is slow) and does some basic math, you want to compile functionB. Well… you can always compile both in any case :).