About this image
Because arguing never stops. And I saw some people throwing poopoo at me for using GameMode quest scripts with fast delay, and "oh no too much code why not move it into UDF?"
So this is it. UDFs are executed in a single line, which is way heavier than normal quest (or even effect) script running with lowest possible delay in GameMode
Case closed. Your fancy UDF mods are slow(er).
Tests made with Code Comparer by Cipscis
18 comments
compare to
?
Or -=, or /= or *=, for that matter.
Thank you for posting this, Xil.
Problem is - it all adds up eventually, mod after mod.
But you are free to use whatever you want, just keep in mind that people don't read your code. People *play it*.
But you are doing your future self a favor. I can't remember how many times I came back to a mod that I've made years ago and couldn't understand jack s#*! from the code. UDFs really help me in structuring the flow of my scripts.
Btw, I noticed you don't use the let keyword for assignments. I always use it because if some operation fails, you are informed in the console. With set, it will be a silent fail. But I guess you already know this so... any reason for that?
https://i.imgur.com/zHr9i64.jpg
From my experience, I can firmly say that let has probably saved me from tens of hours of debugging. That's because it discovered many division by zero errors. Errors that I would have never caught with set.
Still, for operations such as "let var += 1", I think you would be better off just typing "set var to var + 1". I can't see how that would ever fail.
In one of my mods I am using a user-defined function to calculate fully modded DPS on a weapon. I've sorted 5 arrays containing ~60 weapons each multiple times with two different functions for it, one using mainly set (https://pastebin.com/U3aKZrpd) and the other using only let (https://pastebin.com/LLzMqsMa). It would consistently take 6-7 seconds to complete using let, but using set it was under 2 seconds every time I tried.
I was quite surprised by the difference, though. Taking into account the delays added by every other function, "set" is probably in the ballpark of 8x faster than "let".
Well sure it would not be a problem if our modusers were using limited amount of scripted mods, choose them wisely, and so on. But no, what we see is a picture of 130-death limit amount mods, lots of them merged, and topped with Solid. That's a recipe for disaster. One mod uses let by default, several others just pump the game with UDFs, few more just pure heavy math ones - and there you have it, low fps and instability all over the place. Because it all adds up.
Don't get me wrong, I'm not saying "stop drop and roll, forget about UDFs, let, events, them all bad", no. But if you don't need it (or if you need it solely for readability) - don't do it. Keep it simple, use slicing to speed it up, comment it well (if you need to navigate it easily in the future).
I guess only one solid "NEVER DO IT" is SetFunctionValue SomeValueOrRef inside UDF. It's a killer, you see the result on the picture. Use Set QuestName.MyReturnValueOrRef to SomeValueOrRef instead. It's insanely faster.