Jump to content
The simFlight Network Forums

Lua stutter


Recommended Posts

Hi.

Whenever I trigger a lua file, I get a small pause in the sim - maybe about half a second. This happens even if the lua file is precompiled.

I am using:

UpdatedByVersion=5121b
FSVersionUsed="Lockheed Martin® Prepar3D® v4",4.1.7.22841
SimConnectUsed=4.1.0.0

The size of the lua file doesn't matter.  Even an empty file will give a short stutter.   My FSUIPC5.ini is attached.

Grateful for any thoughts or suggestions.

Cheers,

Bryn.

FSUIPC5.ini

Link to comment
Share on other sites

13 hours ago, Bryn said:

Whenever I trigger a lua file, I get a small pause in the sim - maybe about half a second. This happens even if the lua file is precompiled.

I am using:

UpdatedByVersion=5121b
FSVersionUsed="Lockheed Martin® Prepar3D® v4",4.1.7.22841
SimConnectUsed=4.1.0.0

The size of the lua file doesn't matter.  Even an empty file will give a short stutter.   My FSUIPC5.ini is attached.

Well, that's a new one. I've never seen or heard of any sort of hesitation caused just by invoking a Lua plug-in.

A request to run a Lua plug-in is implemented by first creating a new thread. It is that thread which then loads and executes the Lua code. The Lua threads are at a lower priority that the main sim, so really should not have any noticeable affects on performance. Of course, it can later, depending on what it does.

The disk access to load the file should not be causing it unless it interferes with some disk accesses being made by the main sim. To check this, does the "empty file" Lua cause a stutter on subsequent loads, or only on the first (the later ones sohuld get the file from a cache, unless you've turned Windows file caching off)?

It is a puzzle. Could creating a new thread be causing some delay, some conflict? Maybe Windows is already running near its maximum number of threads (whatever that might be)? Are you running many things simulataneously? Many Lua threads simultaneously?

In case it is something to do with processor contention, you could try adjusting the Affinity Mask for Lua threads (LuaAffinityMask parameter in the [General] section of the INI file). That needs to be a subset of the processors assigned to P3D (all of them if the P3D Affinity Mask is defaulted).[Ah, looking at yout INI you'd already set that. Might be a good idea to restore iit to 0, to default, as a test, as most folks will have it like that]

I don't know what your application is for the plug-in, but one thing to consider, for greater efficiency in any case, is to use the event system to operate it, and have it loaded during initialisation, using an [Auto] section in the INI. Then it is only loaded the once, and resides in memory in a suspended thread, just waiting for the appropriate triggers.

Pete

 

Link to comment
Share on other sites

Pete,

Thank you for such a detailed response.

Using the event system was new to me. I tried it, and it worked well, eliminating the stutter. 

The empty file was causing a stutter on subsequent loads, and caching is on. I had tried setting my LuaAffinityMask away from processor 0 (which consistently runs at 100% when P3D is running). Perhaps it was a windows defender or virus protection issue.

But not to worry - the event system worked; I learnt something new; and I have ideas about different implementations for other things I have as well now! :)

Thanks very much,

Bryn.

Link to comment
Share on other sites

Pete,

I too have been experiencing this issue - stutters when triggering a lua file. The file I am using is triggered when pushing the joystick forward to press the brakes (so it's assigned to an axis). When I remove it from the axis assignment the stuttering goes away. Weird, and I never noticed it before updating to P3D 4.1. I tried the above [Auto] but it doesn't work in my case (unless I am doing something wrong or missing something). This is the only lua script I have running so I don't think it's colliding with another. Using 5.1.2.102

Jonathan

Edited by jonathanfe
Link to comment
Share on other sites

2 hours ago, jonathanfe said:

I too have been experiencing this issue - stutters when triggering a lua file. The file I am using is triggered when pushing the joystick forward to press the brakes (so it's assigned to an axis)

Ah, if you assign the loading of a Lua plug-in to an axis, then for each change in the axis as you move it, it is killing the previous incarnation of the plug-in and reloading it! It might be trying to do that 20 times a second (the axis scan rate, by default)!

It is doing that because in effect that is what you are telling it to do.

To use an axis value for a Lua, use the event system. Assign the axis to LuaValue, which will set the ipcPARAM is the Lua for it to use. Use an event.param function to handle it. Preload the Lua plugin using an [Auto] section in the INI. You can make that profile-dependent if necessary - [Auto.profilename].

Pete

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.