Hello there.
For some reason my game is stuttering (on Android) when a function is called for the first time… I’m sure the problem is not my code (me and a lot of other people reviewed the code exhaustively for something but we couldn’t find anything) and I’ve even tried not creating local vars at all in order to make sure the problem isn’t some weird GC behavior.
Most times something is done for the first time the game stutters, the more demanding is the function the longer is the stutter, so when you jump, run, shoot, pick a weapon, etc. the game will stutter at the first time but will run smoothly afterwards. The most notable is the function to aim the nearest enemy and shoot, it stutters even on fairly powerful devices and on the Galaxy Pocket Plus it stutters for like half a second. Even on the GalaxyPP though the subsequent shots will run smooth as butter.
The functions doesn’t do anything different on the first call… Here is the function that is called when the player stops running; it stutters a bit (on the GPP):
function CMDWalk(){
running = false; //boolean on this script
if(!animation.IsPlaying("jumping")){
animation.Play("walking");
}
curspd = runspd; //floats on this script
animation["bobbing"].speed = 1;
}
While the function to shoot the nearest enemy stutters on all devices, it calls lots of other function on other scripts and I don’t think it’s necessary to post them here because the problem doesn’t seem to be the functions themselves.
It seems to me that the problem is the JIT compiler which compiles the stuff for the first time when you first call them, of course I could simply call all the function at the startup but that’s not simple because most functions are dependent on things that must be initialized properly like pools and they need correct parameters and stuff (e.g. the ‘shoot’ function calls ‘firebullet’ on the ‘shooting’ script which calls the ‘pools’ to create a bullet and it should pass the ‘type’, ‘speed’, ‘position’, ‘damage’, ‘color’ of the bullet).
Is there an easy way to deal with that problem?
Note: I’m using 4.5.2f1