Script Caching

When you try to decide which scripts to use with the new script caching feature (Module->Properties->Cached Scripts) you'll need to know how it works:


To put it simply, this functionality allows you to cache compiled scripts (.ncs) into RAM, thus speeding up their execution time.


Do


Do cache those scripts that are used most frequently in your module. For example onHeartbeat scripts, onSpawn scripts for commonly used monsters and so on should be cached, whereas caching an onRested event script may not yield any noticeable performance increase at all.


Do cache scripts, even for single player modules. Access time to scripts held in memory (ie caching) is way faster than access time to scripts on a harddrive. So, the more often a script is called (by a player, a creature, etc), the more performance gain you get. This gain is perhaps more noticeable in multiplayer because more things are happening and more scripts are being run, but you will get benefits even in single player.


Don't


Don't cache '#include' files. They are not actually compiled as such, in fact they can't be, as there is no 'void main' function. The '#include' files are actually treated as if they are part of the script that uses them, and are compiled as part of that script. So for example, nw_i0_spells is used in many of the nw_s?_* spellscripts, so a copy of the code in nw_i0_spells is placed inside every nw_s?_* spellscript that '#includes' that file and then the whole script is compiled.


Don't cache too many scripts. Each cached script takes up a little bit of RAM on your computer, so, the more RAM you have, the more scripts you can cache. However, just because you can, it doesnt mean you should. Cache too many scripts, and the game might actually run more slowly. Also, when you distribute your module don't forget that other players may have less memory on their machine than you do.





 author: Georg Zoeller, editor: Grimlar
 Send comments on this topic.