Jump to content

Very specific Papyrus Performance Question


anghelos92

Recommended Posts

Posted

Hi, I am an amateur modder with an interest in scripting but with no formal education in programming or software engineering, I work in an Hospital no IT formation at all but the "How to use a pc for medical use" exam at university xD 

 

I made a mod for AAF, from which it receives an event and do some calculations on an array of actors.

Before doing so I copy the received array into an array of my own sorting the elements into some specific index that I need for my calculations depending on the returned index of the playerref. 

 

Event AAF:AAF_API.OnSceneInit(AAF:AAF_API akSender, Var[] akArgs)
        Actor[] akArgs2 = Utility.VarToVarArray(akArgs[1]) as Actor[]
        Actor second1
        Actor third1	
        If akArgs2[0] as Actor == PlayerREf
		Second1 = akArgs2[1] as Actor
		Third1	= akArgs2[2] as Actor
	ElseIf akArgs2[1] as Actor == PlayerREF
		Second1 = akArgs2[0] as Actor
		Third1 = akArgs2[2] as Actor
	Else
		Second1 = akArgs2[0] as Actor
		Third1 = akArgs2[1] as Actor
	EndIf
       ; [...] etc etc various functions called on playerref, second1 and third1
EndEvent

Knowing that this event return at least an actor array of 1 element (the playerref) so some calculations are always done with it, and that, if the returned array.length is less than three, second1 and/or third1 can be none this can fire an error in the papyrus log about the akargs[2] array being out of range, my question is:

 

What is more performance friendly?

- Let the virtual machine automatically abort the lines with functions called on none actors, consider that I disable papyrus logging in Fallout4.ini? (When the VM abort those function calls because of second1 or third1 are none, the script goes on with its execution without other consequences and just ignoring those lines)

- Or make a serie of If statements to check for the returned array length before doing my calculations?

 

Obviosly the checks before using the returned array would be a better coding practice to at least don't pollute the logs but mine is a pure performance question and I am not 100% sure of doing a correct profiling.

 

I know that probably we are talking about microseconds xD  but curiosity burns.

 

Thank you!

Posted

Keep the IFs.

The VM fail will take more time than an IF.

You can also avoid the unnecessary casts like akArgs2[x] as Actor. The array is already an array of actors.

Posted
2 hours ago, CPU said:

Keep the IFs.

The VM fail will take more time than an IF.

You can also avoid the unnecessary casts like akArgs2[x] as Actor. The array is already an array of actors.

Thanks for the quick response!

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...