• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

What is faster?

Status
Not open for further replies.
Level 8
Joined
Aug 4, 2006
Messages
357
I think locals are (insignificantly) faster to access than globals. However, this is offset by the fact that locals need to be created and destroyed, which takes up time. Local handle variables also need to be nulled at the end of the function to remove the reference leaks. When it comes down to it, it's much more efficient to recycle global variables than to keep creating and destroying locals. With the help of vJASS, you can make private globals in scopes that are a great replacement for locals and can be used in multiple functions.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
locals are faster concerning performance, and locals are often faster to work with.
The difference between the two is negligible though, and if you're looking for performance bottlenecks, you're focussing on the wrong thing if you care about performance differences between locals and globals.
 
Level 3
Joined
Jul 20, 2008
Messages
41
Could reducing the number of globals and converting them to locals reduce in any way the loading time?
 
Level 8
Joined
May 15, 2008
Messages
492
Locals have the advantage of making things MUI while globals need to have all these extra variables stuff added and custom value to make MUI.
 

Rmx

Rmx

Level 19
Joined
Aug 27, 2007
Messages
1,164
Locals have the advantage of making things MUI while globals need to have all these extra variables stuff added and custom value to make MUI.

You mean Indexing in GUI or custom values using globals ext.

Well Locals are much easy to use, but for some people JASS is hard so the use one Local in a GUI trigger as a custom script, but it is only used if the trigger is small and not worth making it indexing, like when unit casts bezerk and you want his hand set up in flame then you make a local unit wait like 8 seconds then remove the hot ability from him ext.
 
Level 5
Joined
Aug 27, 2007
Messages
138
I don't think there's a difference performance-wise. Locals are certainly easier to work with when you have just one function, but globals are easier when you have several. Locals take time to pass between different functions, whereas with globals, that's not necessary.

Here's the bad (but almost negligable) thing about globals: they never stop taking memory.

When you declare a local, it sets aside memory to use to store its information:

JASS:
function forehead takes nothing returns nothing
    local integer i // Oh, hey, let's take away 32 bits of memory (or whatever warcraft ints use) to store this variable in.
endfunction //now we're done with it, give the 32 bits back

With globals, there's no endfunction that magically causes them all to disappear, they're there the entire game (unless you null them [handles only], which means they can't be used anymore). Also, handles such as units use a lot more memory than ints. It's not really worth considering most of the time, but when you have over 100 global variables that are only used in one trigger, it can eat up memory. But, like I said, most people don't have any problems running even the worst Warcraft maps anymore.

Of course, memory leaks with local handles are worse... you have to null those or the game never releases the memory (a unit variable isn't really a unit, it just "points" to the unit, which is actually a combination of reals/ints/bools, etc.) .
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
I don't think there's a difference performance-wise. Locals are certainly easier to work with when you have just one function, but globals are easier when you have several. Locals take time to pass between different functions, whereas with globals, that's not necessary.

Here's the bad (but almost negligable) thing about globals: they never stop taking memory.

When you declare a local, it sets aside memory to use to store its information:

JASS:
function forehead takes nothing returns nothing
    local integer i // Oh, hey, let's take away 32 bits of memory (or whatever warcraft ints use) to store this variable in.
endfunction //now we're done with it, give the 32 bits back

With globals, there's no endfunction that magically causes them all to disappear, they're there the entire game (unless you null them [handles only], which means they can't be used anymore). Also, handles such as units use a lot more memory than ints. It's not really worth considering most of the time, but when you have over 100 global variables that are only used in one trigger, it can eat up memory. But, like I said, most people don't have any problems running even the worst Warcraft maps anymore.

Of course, memory leaks with local handles are worse... you have to null those or the game never releases the memory (a unit variable isn't really a unit, it just "points" to the unit, which is actually a combination of reals/ints/bools, etc.) .

I fail to see any relation to the topic, except you expressing your personal opinion and then going off topic(more like spamming).

You are wrong about locas. As said a couple of times already, locas are slower than globals(insignificuntly but slower).
Here, I will explain to you(though it has already been said in the thread) in detail, using your own code.

JASS:
function forehead takes nothing returns nothing
    local integer i // Oh, hey, let's take away 32 bits of memory (or whatever warcraft ints use) to store this variable in.
endfunction //now we're done with it, give the 32 bits back

Those comments. They are 100% True. And what is more, they almost exactly the same as what warcrafts instructs the CPU.
wc3:"Oh, hey, let's take away 32 bits of memory"
CPU: " Sure thing. Wait a sec for me to do it ... *processor working* ... Here, the adress of the memory is #####.
So that takes time. The same goes for your other comment. While with globals only once is space alocated to variables.

Now see, I say variables not Handles, not objects and etc. Variables as in either one of the primative variable type or the container/pointer of/to Handles.
Actual Handles are another story which has nothing to do with the current topic.
 
Status
Not open for further replies.
Top