• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Does having more variables lag the game?

Status
Not open for further replies.
Level 7
Joined
Mar 16, 2014
Messages
152
I have heard from the grape vine that you want to have as few variables as possible, and that simply having a lot of variables will slow down the game. Does this happen by any noticeable amount? Does it have any validity to it?
 
Level 5
Joined
Mar 27, 2017
Messages
106
A variable takes space in the ram.
If you have tons of variables that are all arrays of the maximum size it can start taking significant amounts of ram but if you are using only a dozen of arrays of the maximum size it is not going to give any problems.(as far as I know)
You can probably use tons and tons of variables that are not arrays.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
A variable takes space in the ram.
If you have tons of variables that are all arrays of the maximum size it can start taking significant amounts of ram but if you are using only a dozen of arrays of the maximum size it is not going to give any problems.(as far as I know)
You can probably use tons and tons of variables that are not arrays.
RAM usage does not degrade performance as long as your system is not memory bound. With Warcraft III using up to 4GB of memory and modern computers having anywhere from 8GB to 16GB that is not a problem. The game will crash long before memory usage starts to degrade performance due to page thrashing.

I have heard from the grape vine that you want to have as few variables as possible, and that simply having a lot of variables will slow down the game. Does this happen by any noticeable amount? Does it have any validity to it?
Due to the way the hashtables work that are used for runtime lookup of variables by the JASS virtual machine, having a lot of variables will decrease the average lookup performance. This is because the hashtable used has a finite bucket count and so more variables will result in more collisions which will add a O(n) like performance factor to variable lookup.

Is it noticeable? For hundreds of thousands of variables quite possibly as the overhead might become significant enough that some systems relying on a lot of variable lookup or assignment might start to perform poorly. That said within the average map use case such number of variables are unlikely. In worst case if it is a problem caused by non-array variables one could write a tool to automatically translate several thousands of such variables into a single array by assigning them each a unique static index.
 
Status
Not open for further replies.
Top