Is using : efficient?

so in my game i use a ton of module scripts, which are full of functions that get called approximately ~ 20 times a second. If using a colon, it automatically passes the keyword self to the function. Although in 99.99% of cases this seems like the smart thing to do, does doing it cause excess memory to be transferred, leading to an extra delay when calling the function?
e.g.

function module:Test(...) -- [uses colon]
     print(self) -- self here returns module, which is redundant in most cases
end
function module.Test(...) -- [uses dot] doesn't pass self; is this faster?
     print(self) -- prints nil since the thing that called it was not passed
end

is it worth using the dot (.) operator to write functions if self is not used at all in the function? is it worth changing functions from colon to dot if self is not used?

Yes, you should use the dot operator when self isn’t needed. You should only ever use the colon operator for when you’re making modules that make use of OOP, otherwise it’s useless.

Hope this helped.

3 Likes

ty, that makes perfect sense, but my question is does it cause any noticeable performance drops if the colon is used excessively instead of a dot?

As far as I know, there is no difference in speed between using the colon vs. the dot operator. However, using the colon signifies it’s a method of a class because of how self is implicitly passed. If what your writing is not a method and self is not needed, it would be smarter to use the dot operator. It’s basically syntactic sugar.

3 Likes

i was always wondering that, thank you both for the good answers.

2 Likes

Using : is usually reserved for OOP but there is zero difference in efficiency. If you use self (except when intentionally defined in the module or function itself), good chance that : may be useful over .

1 Like