Jump to content

Recommended Posts

Posted

Is it better to check conditions with :

 

"Most likely to succeed > (and check subsequent conditions in the same way if applicable) > Return ; "

 

Or with

 

"Most likely to fail > (and check subsequent conditions in the same way if applicable) > Return ; "

 

Or does it just depend on the situation, or negligible?

Posted

It could make a tiny difference in terms of timing.

The "most likely to succeed" approach would be a little bit faster most of the time. But I don't think that that tiny bit of difference could be noticed when actually using the script in the game.

 

But I am not an expert in scripting for FO4.

Posted

It is always good practice to try and be elegant so your solutions can scale with the principle is to pass or fail fast with minimum resources (as many delayed native script functions take one display frame to execute).

 

The priority depends of your doing pass or fail validations.

 

This is is a significant chunk which has been performance profiled for fail fast with minimum execution budget for a normal distribution of up to 1000 potential input actors (all setters in all workshops);

 

 

  Reveal hidden contents

 

 

Before optimisation with a random order it could take 5 minutes to execute, after is 90 seconds. That's significant.

Posted (edited)

SKK50 related post:

  Reveal hidden contents

 

Edited by ReDragon2013
Posted

No we are into a code complexity and maintenance discussion.

 

There is a trade off in maintaining simple code structure to simplify change/maintenance and extreme performance.

 

The best choice depends if the code is designed the CHANGE or designed to LAST.

 

SKK code is generally designed to CHANGE as I like to tinker and add stuff through the life-cycle as new sh1t comes to light through user adoption and feedback.

Posted (edited)

You wrote: "No we are into a code complexity and maintenance discussion."

 

In my opinion it's always a good idea to split large code (from events or functions) into smaller functions to have a better overview for maintenance.

I am far away to say some code is better than others. But as Bethesda wiki tell us: "Fail fast, fail early!", "Certain operations, like casting, are faster

then others" and "If you perform an operation and the result .. isn't going to change, .. .Store the result in a variable and re-use the variable where needed.

Prefer to store the variable in a function instead of your script to reduce memory costs and reduce persistence" (like References).

https://www.creationkit.com/fallout4/index.php?title=Performance_(Papyrus)

 

condition samples

IF (ThisWorkShop != None)      ; its comparing with Null-Ref, need a neg operation and need also additional temp bool 
     ; Ref is valid
ENDIF
IF (ThisWorkShop == None)      ; its comparing with Null-Ref and need additional temp bool
ELSE
     ; Ref is valid
ENDIF
IF ( ThisWorkShop )           ; fastest way while Zero flag will be checked only
    ; Ref is valid
ENDIF
IF (ThisActor.IsDisabled() == TRUE)  ; native function with using additional boolVar comparing
   ; actor disabled
ENDIF
IF ThisActor.IsEnabled()      ; convenience function, similiar to "IF !ThisActor.IsDisabled()"
   ; actor enabled
ELSE
   ; actor disabled
ENDIF
IF ThisActor.IsDisabled()
   ; actor disabled
ENDIF

I am sorry, but the papyrus compiler is not generating the fastest code for same condition logic. It generates code as the script coder has written.

Edited by ReDragon2013
Posted

In my experience I loose money on projects and can't feed my kids when developers craft overly complex code that less clever people are unable to maintain. Starvation experience vs opinion.

  • Recently Browsing   0 members

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