Search code examples
lualua-table

Performance impact of using Colon vs Dot for function declarations in large lua tables


I've developed the habit of declaring almost all of my modules' functions with a colon rather than a dot, but I don't use much OOP and almost never use "self". It seems redundant that self gets passed as a parameter every time I call a function, especially if the tables are quite large.

Is there any performance impact with this? Is it worth changing all my function declarations to use a dot?


Solution

  • There's not much of a performance impact to passing a single additional table reference to a function. This is regardless of the table size, as the table doesn't get copied.

    Rather than performance, this seems to be a question of programming style. It is very uncommon to use the colon-syntax for module functions, as this idiom is clearly meant to be used for actual method calls. As such, a library that uses it where it's not necessary will look very confusing to any other Lua programmer.