Many people will know this, but some don't..
Posted: Fri Aug 26, 2011 8:22 pm
When you set love.graphics(or even love.grahpics.draw) to some variable, and then draw things the speed increases with 30%
[citation needed]GijsB wrote:speed increases with 30%
Sure, every time you use the "." operator you are doing a table lookup.GijsB wrote:When you set love.graphics(or even love.grahpics.draw) to some variable, and then draw things the speed increases with 30%
The performance increase will not even be close to 30% though, because the vast majority of performance loss from love.graphics.draw is the C++ side stuff and the image being drawn, not the function call, which was vrld's point.ivan wrote:Sure, every time you use the "." operator you are doing a table lookup.GijsB wrote:When you set love.graphics(or even love.grahpics.draw) to some variable, and then draw things the speed increases with 30%
If you are using love.graphics.draw in a loop a total of 1000 times you are doing 2 lookups * 1000.
However if you store a local reference (local d = love.graphics.draw) the total number of lookups is fewer.
There was a topic about this already:
http://love2d.org/forums/viewtopic.php?f=3&t=3500
Code: Select all
local g=love.graphics
Yes, you can confuse the hell out of people reading your source (including future!you).miloguy wrote:at the top of all my games actually benefits more that just letting me not type as much?
Without the 'local' keyword it's still accessing the global stack, which will not increase performance very much at all, and again the vast majority of CPU time spent when calling love.graphics.draw is doing the C++ and GPU side stuff to actually draw the image, rather than the Lua call.GijsB wrote:Robin,
lovegraphics = love.graphics
(or lovegraphicsdraw = love.graphicsd.raw)