Many people will know this, but some don't..
Many people will know this, but some don't..
When you set love.graphics(or even love.grahpics.draw) to some variable, and then draw things the speed increases with 30%
Re: Many people will know this, but some don't..
[citation needed]GijsB wrote:speed increases with 30%
Re: Many people will know this, but some don't..
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
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Many people will know this, but some don't..
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
Re: Many people will know this, but some don't..
So my
at the top of all my games actually benefits more that just letting me not type as much?
Cool
Code: Select all
local g=love.graphics
Cool
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Many people will know this, but some don't..
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?
Oh, you were talking about benefits?
Help us help you: attach a .love.
Re: Many people will know this, but some don't..
Robin,
lovegraphics = love.graphics
(or lovegraphicsdraw = love.graphicsd.raw)
edit :
i mean =
local lovegraphics = love.graphics
(local lovegraphicsdraw = love.graphicsd.raw)
lovegraphics = love.graphics
(or lovegraphicsdraw = love.graphicsd.raw)
edit :
i mean =
local lovegraphics = love.graphics
(local lovegraphicsdraw = love.graphicsd.raw)
Last edited by GijsB on Sat Aug 27, 2011 7:23 pm, edited 1 time in total.
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Many people will know this, but some don't..
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)
Re: Many people will know this, but some don't..
slime,
my bad, i forgot the typing local...
my bad, i forgot the typing local...
Re: Many people will know this, but some don't..
This should be done in specific situations where many calls to love.graphics.draw are made, and then the local variables should be declared in the smallest possible scope. However, if you're going to do lots of love.graphics.draw in one place, you should probably draw it to a framebuffer and draw that afterwards anyway (depends on the situation of course).
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Who is online
Users browsing this forum: Ahrefs [Bot], Google Adsense [Bot] and 5 guests