Jump to content
Sign in to follow this  
Thomas Kaira

[Skyrim] Optimizing your scripting

Recommended Posts

I recently received a message over Steam about a very informative article concerning the new method Papyrus uses to execute scripts and how to optimize scripts to reduce update lag.1. If your script must run constantly, but does not need precise timing, use RegisterForSingleUpdate() instead of RegisterForUpdate().2. Localize your variables. Only declare variables as global for your script if it is used in more than one Event or Function block. Otherwise, consolidate your variables and declare them only where they are needed.3. Consolidate your Getters. This is one of the reasons the TESV.EXE was so inefficient before TESVAL came along, Getters were used all over the place and were slowing the game down. The same holds true for scripting, if you use a whole bunch of Getters, you will bog down Papyrus and potentially cause update lag. Wherever you can, declare your Getters to a variable and then reference that variable to help speed things along (only if you use a specific Getter, such as game.getPlayer(), more than once).4. Use "Return" as much as possible. Whenever you have an area of your script that if the conditions are good, you can immediately stop the script there, put a "Return" in. Otherwise, Papyrus will execute the entire script anyway, so telling Papyrus where it can stop can be quite helpful.You can read the full article here.

Share this post


Link to post
Share on other sites

Not bad advise, but it does seem to me that some of this is a bit paranoid and only applies to scripts that require regular updates.BTW, the "getters" that TESV.EXE are using aren't really the same thing as these here in Papyrus as far as I know. They're actual C++ functions, and that stuff operates at a much lower level than anything we can write. The problem the game executable had was that it hadn't been optimized to inline those calls so they execute faster.So far everything I've written is only going to execute once, and it's pretty small functions overall. Bethesda could easily help solve this by making the Papyrus compiler do the same kind of inlining that sped up the game itself.Something else I thought about. Fragments. How do they factor into everything?

Share this post


Link to post
Share on other sites

Yeah, we don't know how the engine handles fragments.Localizing variables is good practice in the O-O world anyway. Trying to track down when some script or process modifies a global is a nightmare. I don't believe getters would slow the game down either. Once again in O-O programming, they are a must. All variables should be private to a class and you would use getters and setters to access and alter them. Once again, I don't know how the game handles them though. Using Return is probably a pretty good idea, although once again a proper O-O language wouldn't need such a thing.

Share this post


Link to post
Share on other sites

True, it's probably best to make sure your stuff remains in as tight a scope as it can in order to minimize debugging nightmares. That sort of philosophy works just fine if you're writing actual functions into your scripts. Especially if you know that you won't need them outside of those functions. There's no sense in having a laundry list of properties if you don't need them. Especially since properties can cause other issues like unintentional persistence on an object reference.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

Support us on Patreon!

Patreon
×
×
  • Create New...