lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

IIRC the issue of how much metatables affect OOP performance comes up every so often and IIRC the answer generally works out that if you want maximum speed and true data privacy, use closures instead of tables to represent your objects. If you want convenience and a bit more hackability, use metatables.

Do I remember these discussions correctly?

If SteveD is around (having recovered from Rust), I have a sneaking feeling that he will know and may even have some carefully measured numbers of his own.

I occasionally program in “closure style” (utilities and one-offs only, no serious projects) for the same reasons I sometimes ride my folding bicycle even when I know I won’t need to fold it: just to be different, and because I can. 

Once in a while the foldie is fine for outings without planes or trains in them, and it pays to keep your hand in (and check if anything needs maintenance), but in general I prefer to ride a regular bike.

Same with tables of data (if I want to peek inside I can) with a common metatable of functions (if I want to peek inside I can) over closures.

The metatable way is self-documenting and it’s simple to hack or bodge objects if needed.

If performance truly mattered I would suppress my personal preferences, get out a stopwatch (metaphorically, of course) and choose the faster of the two if the time difference clearly and reliably exceeded 12%.