🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Performance hit associated with lua?

Started by
7 comments, last by nekoflux 20 years, 3 months ago
Heres another question: I was recently looking at the process tree for my engine, and I noticed that there are about 5 threads that spawn besides the main program thread. This seems highly excessive. I''m using several libraries (fmod for sound, ode for physics, lua for scripting). I don''t think ode spawns any threads, and fmod is only spawning 2 at the most. Which leads me to believe that lua has several threads that executing at runtime. I''m assuming these are for garbage collection, coroutine execution etc. But Im not using coroutines in my engine, nor will I, ever. Is there a way I can turn off these extra threads or force them not to run? I never, ever want threads in this particlar engine. I get a strange hiccup every 10 seconds or so while the engine is running, and Im thinking this is probably lua''s garbage collector thread taking a little too long to free memory, thus impacting the performance of my system. Is there also a way to turn off the garbage collecting thread? -N
nekoflux
Advertisement
http://lua-users.org/wiki/LuaDirectory

There are two profilers under ''Tools'' and just below that are two articles on optimization and using lua in real-time.

I think you have it backwards but I could be wrong because I don''t know how long deallocation takes, but usually allocation is a bottleneck.

As far as the threads, I can''t think of anything off the top of my head but you do have the source and there might be something in the mailing list archive

http://lua-users.org/lists/lua-l/

Again, I don''t know, but I think ODE does spawn a thread in case there are bad framerates.

Also see Section 3.7 "Controlling Garbage Collection".

I''ve been assuming you''re using lua 5.x
Lua does not spawn threads, even for coroutines. Since it doesn''t use OS-specific functions, it can''t. Most likely fmod is responsible for those extra threads. It''s not hard to check, tho; just look in the stack trace of each.

"Sneftel is correct, if rather vulgar." --Flarelocke
sneftel:

I am skeptical of your claims that lua does not spawn any threads. How else could it implement threading within the scripting language if there was not a monitor thread in the background resposible for time slicing, etc? Also just because lua is cross platform does not mean that it cant or doesnt call platform specific APIs. A lot of code I''ve seen that claims to be cross-platform does something like this:
#ifdef _WIN32  #include <windows.h>#ifdef _POSIX  #include <sys/pthreads.h>...#endif


granted the above is pseudocode, but it illustrates the point. If coroutines are thread implementations then it seems to me that the only way to have more than one routine executing in realtime is to have at least one monitoring thread running thats swaps tasks out for a given VM instance.

any thoughts?

-N
nekoflux
Lua does not spawn threads by itself. Lua does however support using multiple threads by offering functions to create multiple call stacks and other facilities required for concurrent execution. The same functionality is used to implement co-routines. If you desire to execute multiple flows of control concurrently use the co-routine/thread creation functions proided by Lua and start executing multiple functions in different threads that you created yourself using the appropriate system dependent apis.

-- best, Chris
quote: Original post by nekoflux
I am skeptical of your claims that lua does not spawn any threads. How else could it implement threading within the scripting language if there was not a monitor thread in the background resposible for time slicing, etc?

Coroutines are not OS-level threads. They do not execute concurrently with other coroutines. A coroutine simply has the ability to suspend execution and return control to C without returning from the entire callstack.
quote: Also just because lua is cross platform does not mean that it cant or doesnt call platform specific APIs. A lot of code I''ve seen that claims to be cross-platform does something like this:

Lua doesn''t. Check the source if you want. There''s some newer dynamic-loading stuff that''s OS-dependent, but that feature is optional.

"Sneftel is correct, if rather vulgar." --Flarelocke
ok, thanks for clearing that up. Any ideas on how I might be able to track down what is creating those threads? I wasnt able to gain much insight from the sparse information gleaned off the process tree in win xp.
nekoflux
As I mentioned before, look at the stack traces for each thread in the debugger.

"Sneftel is correct, if rather vulgar." --Flarelocke
If your using Direct X, it spawns several threads at startup. They don''t take up any CPU, and I dont know why it does ,proably for some internal reason.

-ddn

This topic is closed to new replies.

Advertisement