I've been thinking about my lower level design of my game a lot from the beginning. I chose to implement all my methods that return x,y coordinates as:
Code: Select all
function whatever:get_location()
return {self.x, self.y}
end
However, obviously get_location() functions are called LOTS of times per gametick on LOTS of different items. And each time, a table has to be created. So I'm making something on the order of thousands (millions? I honestly don't know) of tables per second just to return x,y pairs.
I'm not far enough to know if this will effect performance. I'm guessing it won't, not noticeably. But I can't help but think of it and ask people who might know more.
So how much overhead does simple table creation create? If I switch to multiple return values (i.e., say
Code: Select all
return self.x, self.y
Code: Select all
return {self.x, self.y}
Thanks!
EDIT: and how could I forget to mention function overhead? By calling a get_location() function on tons of objects every frame, I'm incorporating function overhead and table generation at the same time, when I could just be doing object.xy to directly access the table. Is it worth eliminating all that function overhead for slightly less readable and more confusing code?