zarqon
Well-known member
I really like mafia's static variables. I enjoy being able to reduce the amount of "loading time" a script needs.
I've found myself wishing, however, that they would be even more static. At the moment, if I have a script loadstuff.ash that processes some data into a static map variable, and then call dostuff.ash, which imports loadstuff.ash, loadstuff will do all its loading work into a static variable. Now, I call printstuff.ash, which also imports loadstuff.ash. Rather than use the stored static variable (which is associated with dostuff.ash), it does all the work again and creates the same static map again, only this time associated with the name printstuff.ash. There are now multiple copies of the map in memory, which is being used identically by all scripts that reference it.
I haven't been able to think of a compelling reason why it may be undesirable to simply associate the map with loadstuff.ash, so that regardless of whether dostuff or printstuff was called, it would access the same static variable.
For example, ZLib and BatBrain get imported into a variety of scripts, which means the benefit of using static variables there is reduced. ZLib's script settings are loaded once per script that imports ZLib rather than just once. BatBrain's factors map probably gets loaded a good half a dozen times for me during normal play. So after using 10 scripts that import ZLib, users will have 10 copies of vars in memory. This seems like it could be improved by consolidating the duplicates.
So! I would like to request a change to the behavior of static variables, to be per session rather than per calling script. Thanks!
I've found myself wishing, however, that they would be even more static. At the moment, if I have a script loadstuff.ash that processes some data into a static map variable, and then call dostuff.ash, which imports loadstuff.ash, loadstuff will do all its loading work into a static variable. Now, I call printstuff.ash, which also imports loadstuff.ash. Rather than use the stored static variable (which is associated with dostuff.ash), it does all the work again and creates the same static map again, only this time associated with the name printstuff.ash. There are now multiple copies of the map in memory, which is being used identically by all scripts that reference it.
I haven't been able to think of a compelling reason why it may be undesirable to simply associate the map with loadstuff.ash, so that regardless of whether dostuff or printstuff was called, it would access the same static variable.
For example, ZLib and BatBrain get imported into a variety of scripts, which means the benefit of using static variables there is reduced. ZLib's script settings are loaded once per script that imports ZLib rather than just once. BatBrain's factors map probably gets loaded a good half a dozen times for me during normal play. So after using 10 scripts that import ZLib, users will have 10 copies of vars in memory. This seems like it could be improved by consolidating the duplicates.
So! I would like to request a change to the behavior of static variables, to be per session rather than per calling script. Thanks!