of     2   
chevron_rightchevron_rightchevron_right

XlegoX
#8220049Monday, May 04, 2009 10:54 PM GMT

Here's a short but usefull optimization. At the very start of your scripts, put this: local game = game How you may ask? Because in Lua, accessing global values takes about 10 times as long as accessing local ones, so if you make a local copy of game, all of the indexes of "game" your script makes will run 10 times faster. Neat eh? -xLEG0x === *WHY* it works, warning technical details beyone this point === The reason that accessing globals takes longer than accessing locals is that locals are stored as an *exact* position in your computer's memory, but globals are stored as an "identifier" to a global table. When Lua wants to access a local, all it has to do is look at the adress in memory that the local should be stored at. On the other hand, when it wants to access a global, it has to search through the table. In Lua, tables are stored as "next-last-key-value" packets. They have two pointers to the next and previous values in the table, what index the current packet is, and what value the current packet is storing. So when Lua has to find a specific index in the table, it has to look at every other index until it gets to the one you want. That means the more stuff there is in the global environment, the more stuff has to be searched through for Lua to find the global you want. So, basicaly, if you use an index more than once, you should declare it as a local varaible, and it *will* increase performance.
quantumnerd
#8220087Monday, May 04, 2009 10:54 PM GMT

NEAT... I'll keep this in mind. Thanks!
Meelo
#8220114Monday, May 04, 2009 10:55 PM GMT

Ever since he posted this on the other scripting help, I've become an optimization freak.
Aeacus
#8220136Monday, May 04, 2009 10:55 PM GMT

Awesome, I never knew that would help :D
blobbyblob
#8220157Monday, May 04, 2009 10:56 PM GMT

Ooh, very fancy. I think I'll have to implement that into my scripts.
level140roblox
#8220166Monday, May 04, 2009 10:56 PM GMT

Uhh, repost? You did this before... in script help...
earth100
#8220229Monday, May 04, 2009 10:57 PM GMT

Would local Workspace = Workspace Work as well?
XlegoX
#8220250Monday, May 04, 2009 10:57 PM GMT

Yea, this explaination is slightly better though, the last one was a bit sloppy, and it's better suited in this new forum.
MicroUser
#8220273Monday, May 04, 2009 10:57 PM GMT

[ Content Deleted ]
XlegoX
#8220279Monday, May 04, 2009 10:57 PM GMT

"Would local Workspace = Workspace Work as well?" As I said at the end, *any* value you use more than 1 time would be worth it...
MicroUser
#8220304Monday, May 04, 2009 10:58 PM GMT

[ Content Deleted ]
dwighterz
#8220422Monday, May 04, 2009 11:00 PM GMT

Very good idea. I could never have thought of that.
PiePersonofDOOM
#8220793Monday, May 04, 2009 11:07 PM GMT

10 times faster you say? Dang. That's so cool.
Clone512
#8220794Monday, May 04, 2009 11:07 PM GMT

So many people don't believe me when I say local variables aren't useless and they run faster, maybe now they'll believe me.
rockapprangr2
#8220805Monday, May 04, 2009 11:08 PM GMT

Nice. I would have to keep this in mind, instead of leaving the top blank.
sonic911
#10954144Saturday, July 11, 2009 7:42 PM GMT

now i understand
sdfgw
Top 50 Poster
#10954271Saturday, July 11, 2009 7:44 PM GMT

Bump phail? Man, I always knew locals were accessed quicker, but I never thought of that :P
sncplay42
#10954467Saturday, July 11, 2009 7:48 PM GMT

@sd: I didn't realize this was a bump at first, and then I saw level and thought, "What?"
sdfgw
Top 50 Poster
#10954492Saturday, July 11, 2009 7:48 PM GMT

xD Me too.
Person299
#10954627Saturday, July 11, 2009 7:51 PM GMT

Wow, good idea.
sncplay42
#10954663Saturday, July 11, 2009 7:51 PM GMT

I often make functions local.
TaslemGuy
#10954872Saturday, July 11, 2009 7:56 PM GMT

hm... Never considered this.
Snateraar
#10955046Saturday, July 11, 2009 7:59 PM GMT

Grammar police! Basicaly = wrong basically = correct >.< And I never thought of this optimization...
PurpleKiwi
#10957217Saturday, July 11, 2009 8:40 PM GMT

Ooh! Thanks!
objection234
#10959921Saturday, July 11, 2009 9:26 PM GMT

Good idea X X

    of     2   
chevron_rightchevron_rightchevron_right