3

I've embedded the LuaInterface project into an application written in C# using .NET Framework 4.0. After compiling LuaInterface and Lua 5.1 I've referenced them in my application and created a Lua VM and exposed a few .NET classes. When the Lua VM doesn't make many calls, performance is not affected at all; but when it starts to call a larger number of .NET functions the entire application becomes slow and unresponsive.

In response to this, I've made an additional thread to run the Lua VM on. For some reason though, the thread on which the GUI is updated will not update while Lua is doing a function call, resulting in stuttering in the GUI. When moving a window around, you can clearly see that it doesn't respond for a little while, then moves, doesn't respond, etc.

How can I solve this issue? I was under the impression that giving Lua its own thread, a different thread shouldn't be affected! Is this purely related to my own code in some way? Does LuaInterface have a some serious issues calling .NET functions (performance-wise)? What else could I use?

Deathspike
  • 8,582
  • 6
  • 44
  • 82
  • Could we have some examples of your code? – James T Oct 21 '10 at 01:55
  • There are several `if`s. System CPU load, how many cores do you have available (just one?), is the program waiting on results from the Lua code, is the Lua code interacting with the message-queue of the main app, etc. The InterOp call itself should not block other threads, btw. (However, doing InterOp calls requires some some GC objects to be "fixed" (must not change the memory location), so depending on the type of use of it the GC performance may get worse ... but _usually_ not in such large amounts. – gimpf Feb 22 '11 at 14:44

1 Answers1

0

I didn’t try to compile LuaInterface against .NET 4. So far I used only the precompiled dlls. I know that you can speed up mixed image assemblies in .NET 4 by setting the to zero. According to MS: .NET Framework 4, a streamlined interop marshalling architecture provides a significant performance improvement for transitions from managed code to unmanaged code.

http://msdn.microsoft.com/en-us/library/ff361650.aspx

Keep us updated in case you find a trick which works for you. In Visual Studio 2010 you can actually build against .NET 2 so if I were you I would try to create a dummy app and compile it against multiple targets. It might help you to quantify the speed degradation when you are using .NET 4.

If you give us some code maybe I could play with it a bit and figure out what is wrong. I am really interested in LuaInterface and keen to figure out what is wrong.

Since I don't have a code sample I am just speculating on this; but it is possible that the issue is related to your UI not being thread safe. It is pretty common to have locking issues for example with Windows Forms Controls.

How to: Make Thread-Safe Calls to Windows Forms Controls http://msdn.microsoft.com/en-us/library/ms171728(v=vs.80).aspx

Jeno Laszlo
  • 2,023
  • 18
  • 36
  • "I know that you can speed up mixed image assemblies in .NET 4 by settting the ____ to zero" -- The what? Don't leave me hanging! :-) – Cameron Feb 14 '13 at 19:46