Originally Posted by
kung foo man
If you suspect some code to be slow, just add some wait 0.05; in there (like, when if (i == 10) wait 0.05;), so the game engine has some time to care about the other events and later just resume the loops.
Or generally, optimize the code. In computer science there is always more than one way to do stuff. To know what to optimize, there first need to be a profiler tho (or some good wild guesses). Probably would be a nice addition to measure time in all kinds of functions to create "fire graphs"... to see where it burns the most.
Random idea I just got: make some function, which measueres the time till "last reset". So before entering performance critical code, the timer is reset. And IN the performance critical code, you can check all the time how much time was spend already, like in every loop body. If the time passed e.g. more than 10 milliseconds (which is quite alot, consider that a frame is only 50ms and there are others threads/coroutines which need to work aswell), then just "drop out" via wait 0.05 and reset the timer.