generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Storing Properties as Variables Efficiency?

Previous Thread :: Next Thread 
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
25 Dec 2015 12:16 PM
Hey guys,

As I was programming, I noticed I used a lot of .Parent's, .Name's, etc. Then I wondered if it would be more efficient to store the properties as variables.

Let's take this example:

--Without Variables
local Part = workspace.Part;
if Part.Name == "Part" then
print(Part.Name)
local PartInStorage = game:GetService("ServerStorage"):FindFirstChild(Part.Name, true);
end

--With Variables
local Part = workspace.Part;
local Part_Name = Part.Name;
if Part_Name == "Part" then
print(Part_Name)
local PartInStorage = game:GetService("ServerStorage"):FindFirstChild(Part.Name, true);
end

I know, the difference between the two will probably be unnoticeable but for me it's worth it to know.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
25 Dec 2015 12:26 PM
The performance difference is negligible and your implementation is wrong
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
25 Dec 2015 12:34 PM
It's just an example.

But even if the difference is negligible, it still is a difference! And I would like to know. :P

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
metologyaddict is not online. metologyaddict
Joined: 09 Dec 2015
Total Posts: 378
25 Dec 2015 12:36 PM
[ Content Deleted ]
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
25 Dec 2015 12:38 PM
That is not really the point...

But I already do, a ModuleScript with all my shared variables stored.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
25 Dec 2015 12:40 PM
doing this has a practical limitation in that doing this:

local Part_Name = part.Name

copys the string value 'Name' in part and therefore doesn't change in the case of the part's name changing, like:

part.Name="ayy"
local Part_Name = part.Name
print(Part_Name)
==>ayy
part.Name="lmao"
print(Part_Name)
==>ayy
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
25 Dec 2015 12:42 PM
What about in the scenario where the name doesn't change?

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
25 Dec 2015 12:43 PM
probably. if you know that the value definitely won't change ever, it would probably be a tiny bit faster.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
26 Dec 2015 05:10 AM
It would be like (n-2) lvm instructions faster where n is how many times you use it. Probably a bit less than that, or a bit more, but I don't look at the instructions.

The major difference you're looking at is that the __index won't fall back to C, so everything will be dealt with inside of Lua only.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Dec 2015 05:29 AM
It's not going to make any different unless you actually use it more than once, and even then typically it's not going to be worth it.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Dec 2015 05:30 AM
difference*
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
26 Dec 2015 05:32 AM
I'm using it a few times.

How would it "typically" be not worth it?

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Dec 2015 05:34 AM
In most cases, although there are plenty of cases where it can significantly speed up your code. It's all situational.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
26 Dec 2015 05:39 AM
So if the situation was just to be used for indexing a dictionary, would it be beneficial?

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Dec 2015 05:41 AM
"indexing a dictionary"
Uh, well you need to elaborate on that.

If I have a dictionary:
local x = {a = 5, b = 10}

I don't see how you could possibly make indexing that more efficient using what method you're describing.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
26 Dec 2015 05:49 AM
I have a module script, in this representation it will be known as "IslandData".

It holds information about different islands. Like this:



local IslandData = {};

IslandData["Island1"] = {

Usage = "Holding a nuclear reactor.";
DateFound = "26/12/2015";
etc

};

return IslandData;



And corresponding to my thread about ClickDetector's unreliability. When you're hovering above an island, it will show this information. So like this:

Hovering mouse event, etc.

GUI.Name.Text = HoveringIsland.Name;
GUI.Usage.Text = IslandData[HoveringIsland.Name].Usage;
GUI.DateFound = IslandData[HoveringIsland.Name].DateFound;
etc

Would it better to make "HoveringIsland_Name" as a variable and use that as the index?

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Dec 2015 05:56 AM
Technically it would be better, but you'd also be better making a variable for"IslandData[HoveringIsland.Name]" too
But then it'd be better to disregard all of that and not nest tables if you can avoid it
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
26 Dec 2015 05:57 AM
Would having a folder containing ModuleScripts for each individual island be a better choice to nesting?

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Dec 2015 03:22 PM
Not really, you'd be better off not worrying about this and actually work on whatever you're working on.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image