I am developing a game in which I use C ++ (SFML) for the kernel and Lua for actor scripts. However, I run into some performance issues, and I'm not sure what might be wrong. I created a test program that shows the problem I am having.
Basically, sometimes when I call a Lua function from C ++, it takes a lot more time to return than usual. I need my game to run at 60 frames per second, and this happens most of the time, but sometimes one or more function calls take much longer than usual.
My first thought was that it was a memory manager, but disabling it did not seem to get rid of the spikes. I know that there are several games that use Lua, and I believe that this is not a problem for them.
People suggested that using LuaJIT might solve the problem, so I downloaded and installed LuaJIT (with lua 5.1). I significantly improved the average time, but the spikes were as common as before:

Gallery of 2 examples of console results (in microseconds, for reference: a frame at a speed of 60 frames per second is ~ 16700):
gc off
gc on 
C ++ Testing Program - http://pastebin.com/RhYnnLm3
Lua test script - http://pastebin.com/NBnAXcVD
source share