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

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

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

Post by GijsB »

When you set love.graphics(or even love.grahpics.draw) to some variable, and then draw things the speed increases with 30% :ultrashocked:
User avatar
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..

Post by vrld »

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
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

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

Post by ivan »

GijsB wrote:When you set love.graphics(or even love.grahpics.draw) to some variable, and then draw things the speed increases with 30% :ultrashocked:
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.
There was a topic about this already:
http://love2d.org/forums/viewtopic.php?f=3&t=3500
User avatar
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..

Post by slime »

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% :ultrashocked:
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.
There was a topic about this already:
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.
User avatar
miloguy
Prole
Posts: 32
Joined: Sat Jul 02, 2011 2:09 am

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

Post by miloguy »

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 :D
User avatar
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..

Post by Robin »

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? ;)
Help us help you: attach a .love.
User avatar
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..

Post by GijsB »

Robin,

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

:joker:

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.
User avatar
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..

Post by slime »

GijsB wrote:Robin,

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



:joker:
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.
User avatar
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..

Post by GijsB »

slime,

my bad, i forgot the typing local...
User avatar
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..

Post by T-Bone »

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).
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests