How to explicitly multi-thread papyrus scripts?

Post » Fri Jul 25, 2014 7:30 pm

My mod in development is required to walk through a player's inventory and extract information on each item (type, name, magic effects and their duration) and store this information in a quickly accessible array ie much quicker than using getNthForm or the newer SKSE get all items formlist function.

The problem is, initially collecting all this information from each form using GetType, GetName, GetNthMagicEffect etc on 300+ items is very time consuming, taking about 25-30 seconds.

Now, I know papyrus can multi-thread, so was wondering whether I can explicitly set this up to split the workload across 4 or more threads - eg for a 100 item formlist, process items 1- 25, 26 - 50, 51 - 75, and 76 - 100 all in parallel across 4 threads. What's the best way to set this up to allow parallel processing?
User avatar
Valerie Marie
 
Posts: 3451
Joined: Wed Aug 15, 2007 10:29 am

Post » Fri Jul 25, 2014 5:15 pm

Events will start a new thread. RegisterForSingleUpdate(0.0) is probably the easiest way to create a new thread, and you can use states if needed.

User avatar
Carlos Vazquez
 
Posts: 3407
Joined: Sat Aug 25, 2007 10:19 am

Post » Fri Jul 25, 2014 9:56 pm

Probably the most straightforward method would be to use SKSE mod events to begin each new thread. You can just set up a loop to send off a new mod event each iteration, and each time you send the event it will start a new thread.

Doing that will noticeably improve your speed but it will still probably take awhile to get all that you want to do done -- the Get functions you mention are all going to be delayed functions and there's only so much performance you can squeeze out of papyrus even with multi-threading.

Mojo beat me to it with another good suggestion :smile:

User avatar
Elea Rossi
 
Posts: 3554
Joined: Tue Mar 27, 2007 1:39 am


Return to V - Skyrim