Jump to content

[LE] Which one works faster in a Script ?.


Recommended Posts

 

 

 

This is also, by the by, why manipulating arrays are so much faster than FormLists.

 

 

How would the game handle FormList in your opinion? I think is a safe bet that it places them into Arrays. So by going directly to an Array you are cutting out the middle man.

 

Or is some other way of doing it? Please enlighten me. How does the game deal with Formlist?

 

Mate, seriously, no offense intended, but even a web-page is just a glorified array of data manipulation.

 

 

I would suspect -- I haven't delved into the C code to know -- that the internal guts of FormLists are implemented as a linked list stack in the C code. The publicly accessible APIs suggest it: it isn't fixed-length (and can in fact be arbitrarily large, AFIACT) and insertion always happens at the top.

 

However, that's not relevant here. The reason FormLists are slower than Papyrus arrays is because all of the FormList manipulation functions, such as HasForm() or GetAt(), are both idiot-proofed and frame-linked. Compare the execution speed of calling HasForm() on a FormList, doing an iterative search of that FormList with GetAt(), using Find on an array, and doing an iterative search of an array with ArrayName.

 

Although there is no logical difference between an iterated GetAt() and calling HasForm() -- HasForm() has to do exactly the same steps -- the HasForm() approach is significantly faster, because while HasForm() is frame-linked all of its internal steps are not. On the other hand, GetAt() is frame-linked and can't bundle a bunch of operations like HasForm() does. The upshot of all of this is that, assuming 30 FPS, if you have a moderately long FormList -- say, thirty elements -- HasForm() will return in ~1/30th of a second, but the GetAt() search could easily require a full second in the worst case.

 

Since array operations are all treated as memory accesses, they are not frame-linked (and nor do they allow the thread to jump to another script, which can be important). The difference between using the array Find and RFind methods, and simply coding it yourself directly, is therefore much smaller, and both will be faster than HasForm() is.

Link to comment
Share on other sites

@ foamyesque like Vinnie Barrino I am so Confused weren't you arguing that Formlist were just as fast if not Faster than Arrays? I was saying that not true?

 

Why the eloquent 360?

 

PS I didn't want to mention the functions, cause I I know you hate GetPlayer() & I thought it would pushing it to much?

 

PS2 I know about ListArrays too, but you still treat them has arrays, they just behave different with no set length.(for readers) the ones I use insert at the end or you insert into your desired index position.

 

edit

 

FormLists are just ListArrays (of some sort) with Functions we have an accord :smile:

 

 

This is my last word. Free feel to write an essay.

Link to comment
Share on other sites

Dear Peter,
in March 2019 we had discussed things like arrays:
https://forums.nexusmods.com/index.php?/topic/7478706-help-with-arrays-pls-d/page-2&do=findComment&comment=68778261

There I posted also a link to an older thread from September 2017 which you can find here:
https://forums.nexusmods.com/index.php?/topic/6031618-vmad-or-form-list-which-is-quicker/
cdCooley figured out advantages and disadvantages of formlist and arrays very well !!

 

The important thing is that:

ObjectReferences (and Actors as well) placed in a FormList are not made persistent automatically.

ObjectReferences (and Actors as well) added to an array will be made all of them temporarily persistent.

Edited by ReDragon2013
Link to comment
Share on other sites

The other big advantage of a formlist -- and it is a big one -- is that other game systems, most particularly the condition one, can talk to it. It's also by default dynamically sizable, whereas doing so with arrays requires SKSE or some very kludgey (and limited) code.

 

EDIT:

As in fact I see I said in the 2017 thread you linked, ReDragon :)

Edited by foamyesque
Link to comment
Share on other sites

I do remember reading a post about someone even categorizing the native functions because there are speed differences as well.

Stuff like getValueInt() for example is slower than getValue() because its a badly implemented wrapper function an therefore suffers from fps-linking

(something like @foamyesque's explanation about hasForm() vs getAt() )

 

So if one needs that extra bit of speed this is also something to consider.

Also i think useful info like this: in-depth explanations, good reference links, etc. should be more often made sticky posts or added to the wikis

Every so often you find yourself searching for info like this only to find it buried deep down in some abadoned forum topic, lol

Link to comment
Share on other sites

Has been tested to death in the past. PlayerRef is 1000x faster than Game.GetPlayer(). Also the 'convenience' functions are only convenient in typing speed. GetActorRef -> GetReference() as Actor(), and GetActorReference -> GetActorRef -> GetReference() as Actor. Yes the game will go through all of those steps, so you can see why those kinds of functions aren't very good in practice.

 

Function calls generally are bad when they are called more than necessary. When you expect their values to change throughout a script it's ok to keep using them, otherwise assign to a variable.

Edited by Rasikko
Link to comment
Share on other sites

  • Recently Browsing   0 members

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