## Many people will know this, but some don't..

General discussion about LÖVE, Lua, game development, puns, and unicorns.
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

### 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%

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: Many people will know this, but some don't..

GijsB wrote:speed increases with 30%
[citation needed]
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

ivan
Party member
Posts: 1619
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Many people will know this, but some don't..

GijsB wrote:When you set love.graphics(or even love.grahpics.draw) to some variable, and then draw things the speed increases with 30%
Sure, every time you use the "." operator you are doing a table lookup.
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.
http://love2d.org/forums/viewtopic.php?f=3&t=3500

slime
Solid Snayke
Posts: 2904
Joined: Mon Aug 23, 2010 6:45 am
Contact:

### Re: Many people will know this, but some don't..

ivan wrote:
GijsB wrote:When you set love.graphics(or even love.grahpics.draw) to some variable, and then draw things the speed increases with 30%
Sure, every time you use the "." operator you are doing a table lookup.
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.
http://love2d.org/forums/viewtopic.php?f=3&t=3500
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.

miloguy
Prole
Posts: 32
Joined: Sat Jul 02, 2011 2:09 am

### Re: Many people will know this, but some don't..

So my

Code: Select all

local g=love.graphics
at the top of all my games actually benefits more that just letting me not type as much?
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..

miloguy wrote:at the top of all my games actually benefits more that just letting me not type as much?
Yes, you can confuse the hell out of people reading your source (including future!you).

Oh, you were talking about benefits?

GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

### 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)
Last edited by GijsB on Sat Aug 27, 2011 7:23 pm, edited 1 time in total.

slime
Solid Snayke
Posts: 2904
Joined: Mon Aug 23, 2010 6:45 am
Contact:

### Re: Many people will know this, but some don't..

GijsB wrote:Robin,

lovegraphics = love.graphics
(or lovegraphicsdraw = love.graphicsd.raw)

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
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

### Re: Many people will know this, but some don't..

slime,

my bad, i forgot the typing local...

T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

### 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).

### Who is online

Users browsing this forum: RidgeRava and 20 guests