I'm developing a game where I use (SFML) C++ for the core and Lua for the actor scripts. However, I'm running into some performance issues and I'm not sure what could be wrong. I've created a test program that shows the issue I'm having.
Basically, sometimes when I call a Lua function from C++, it takes much longer to return than usual. I need my game to run at 60 fps, and it does most of the time, but occasionally one or more of the function calls will take much longer than usual.
My first thought was that it was the memory manager, but turning it off didn't seem to get rid of the spikes. I know that there are several games that use Lua, and I imagine this is not a problem for them.
People have suggested that using LuaJIT could fix the issue, so I downloaded and set up LuaJIT (with lua 5.1). I got significantly improved average times, but the spikes were just as prevalent as ever:
Gallery of 2 examples of the console results (in microseconds; for reference a frame at 60 fps is ~16700 I think):
gc off gc on
C++ test program - http://pastebin.com/RhYnnLm3
Lua test script - http://pastebin.com/NBnAXcVD
It looks like you're experiencing LUAs garbage collector rolling in on some of your calls. Typically in games you want to pay very close attention to how the GC operates, and how often it runs. A simple solution may be to manually run the GC once per frame. Some popular game engines I know of do that. http://lua-users.org/wiki/GarbageCollectionTutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With