A question about using tables in function argument

If i pass a table in function arguments like this:

	someNumber = 10;
	something = true;

So will it create a new table every time and affect performance?

Nope. It passes the pointer to the table to the argument.
Otherwise, almost every function from the table standard library will not work.

Thanks, but what if i run this in a loop?

Yes it will allocate a new table each time, Blockzez is only correct if you pass tables like this

local myArguments = {
    someNumber = 10
    something = true


So it would affect performance?

if you have a long loop and big tables then yes it could, a number and a boolean is pretty small. I would worry more about how often you are Instancing roblox objects.

1 Like

I usually do this:

MyModule.CreateInstance("Part", {
	CanCollide = false;
	CanQuery = false;
	Anchored = false;
	--a lot of propertys

When doing instances, does that means i’m wrong all the times?

I would say avoid that, you’re creating two sets of the properties in a Instance. Still the Instance.new("Part") is going to be the performance killer, and the tables likely small hopefully not repeated. any properties set after parenting will hurt but I assume that is partly why you made this RAII style module script.

1 Like

Thanks! Now i gotta improve all scripts in my game and make it better performance!

While you’re there check out roblox’s type checking system, just add --!strict to the top of your scripts, it can catch some tricky errors without needing to run the game

1 Like