• 🏆 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!

[Trigger] Efficiency: multiple variables against an array

Status
Not open for further replies.
Level 10
Joined
Oct 5, 2008
Messages
355
Hey guys, i'm currebtly working around on a system i posted on the hive (GBS) and i'm using around 10 TempInteger variables for managing the whole amount of arrays, ids and counters and keys the system uses.
Now i thought to nyself that instead of declaring single Tempintegers(1,2,3...) i could just go for an array. But im not sure if ghis is more recource saving.
So the Question:
How nany variable declarations do i need to replace to make an array declarstion worthwile?

PS: i know the answer is "learn jass" (i already did btw), but dont let us start on this one, shall we? :D
 
Level 10
Joined
Oct 5, 2008
Messages
355
Thanks for the quick replies. Well, they got a system-specific prefix, so there shouldnt be a problem of collisions with other maps. And i recycle them for various tasks, so i cant give them a single description, unfortunally.
Well, i know some people at the hive are a bit nitpicky ;) , which isnt something bad actually if you want to improve.
Then i can go and clean up my definitions, thats good to hear ^^
 
Descriptive names are good, though I personaly find "TempPoint" worse than just "Point", for example.
It's natural for me to use "Int", "Unit" "Point" or so for natural names for temp variables in GUI.

And if a point is system specific, it anways would require a prefix, so it is okay. For GBS my temp points would be

"GSB_Point1"
"GSB_Point2"

or

"GSB_Point_1"
"GSB_Point_2"

... but if I had 10, I also would probably use an array, though it depends on case I guess.

TriggerHappy did not mean to rename the 10TempIntegers for collision maybe, but just to gain more readability.
Like, when you use the first one for always for counter, then call it something with "Counter" instead of "TempInt", and so on.
 
Level 10
Joined
Oct 5, 2008
Messages
355
Well, at that point, i can rewrite the whole system in jass, because then almost every function call would be a custom script .
(The System in the op doesnt really do that much more than managing data inside a hashtable to be honest)
But since i wanted a GUI System for GUI User, i wanted to do it at least in a fast fashion.
In fact, i was just unsure that i get bashed when i use an array than a low amount of variables more, so i asked beforehand :D

And, to be honest, i still need to fingure out where i can find an easy acesable collection of the natives. Else triggering is more about seeking the right fubctions and finding out what they do than really script writing...
 
Level 10
Joined
Oct 5, 2008
Messages
355
Yeah, i know this. But i wanted to make it in GUI, its not a matter of possibility ^^.

Edit: Since this gone way away from the topic. Can someone recommend a third party tool to assist with jass coding? I mean a good one for highlighting variables etc, at best with some way to look up the natives? I -really- dislike writing codes in the vanilla editor. I see a good amount in the tool section, but currently im unsure which one to take.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
If WC3 had a proper optimizing compiler and proper byte code system, eg C/C++, there would be no difference in speed as they both would compile to the same code.

In WC3 using non array variables is faster as they do not have to evaluate the index argument. On the other hand spamming too many separate global variables (thousands of global variable declarations) can saturate the variable name hashtables, increasing all global variable name resolution times for both array and non array. It really depends on the number of separate variables involved and in any case is micro optimizing.

I would go with readability first, giving variables sensible names and avoiding arrays unless you need to use some sort of dynamic index access. If performance starts to be a problem then one can start to look into optimizing. Chances are that something else is a better target for optimization then variable declaration number. It is pointless spending hours and destroying maintainability to save a few micro seconds every second when optimizing something else could save miliseconds every second and potentially even improve readability/maintainability.
 
Level 13
Joined
Nov 7, 2014
Messages
571
So a map's Jass2 script/text is compiled to bytecode (when the map loads) and executed by a register based VM.
A question that has always* bugged me is why are variables looked up in hashtables instead of them being address in memory/offsets in arrays or something (I don't know how VM are implemented).

* well, not always, but after I've read about it and seen people optimizing scripts by using single letter variable names (which looks totally goofy 0.O?!)
 
Level 19
Joined
Dec 12, 2010
Messages
2,069
So a map's Jass2 script/text is compiled to bytecode (when the map loads) and executed by a register based VM.
A question that has always* bugged me is why are variables looked up in hashtables instead of them being address in memory/offsets in arrays or something (I don't know how VM are implemented).

* well, not always, but after I've read about it and seen people optimizing scripts by using single letter variable names (which looks totally goofy 0.O?!)
blizzards are weird. but yeah, lookup performed everytime, except the code
JASS:
Condition(function myCond)
this one will be compiled strictly, on loading, into static address
JASS:
ExecuteFunc("myfunc")
will lookup for myfunc everytime this line called

not to speak every native is also contained in lookup-index. if you start to care about lookup time you may as well care about nanoseconds.

and short names won't make it better, at least 'cause any sane person would use vexorian anyway in the end
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
A question that has always* bugged me is why are variables looked up in hashtables instead of them being address in memory/offsets in arrays or something (I don't know how VM are implemented).
Possibly to make debugging more readable or some other nonsense. This is why StarCraft II does use direct addressing in its virtual machine, where a variable is compiled to a pointer rather than kept as a name. Unfortunately it also is why StarCraft II has a limit on memory that Galaxy can use.
 
Status
Not open for further replies.
Top