Page 1 of 1

love.graphics.newQuad not so slow?

Posted: Sat May 04, 2013 4:35 pm
by Ref
Was surprised by two things.
The WIKI says the love.graphics.newQuad is:
"This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused! "
I guess 'slow' is a relative term - see demo.
The second surprise was when trying to accomplish the same effect using imageData and paste.
This approach was slower and resulted in a continuous increase in memory usage - ultimate ending in the script stopping dead in the water due to lack of memory. Had to add a garbagecollection step (with resulting periodic hic-up.)
Thought garbagecollection would have been done automatically.

Re: love.graphics.newQuad not so slow?

Posted: Sat May 04, 2013 5:12 pm
by stampede247
Well i'm not sure of the specifics but I left it running for about 45 minutes on my computer, came back and the framerate had dropped from around 980 to between 930 and 940. So something might be slowly slowly bogging it down but idk if that's big enough to really consider

Re: love.graphics.newQuad not so slow?

Posted: Sat May 04, 2013 5:41 pm
by slime
The performance difference between 940fps and 980fps is the same as the performance difference between 60fps and 60.15fps.

Quads don't have a lot of data associated with them or a lot of calculations done when creating them, so newQuad isn't very slow as far as the new* functions go, however as a rule of thumb you shouldn't call new* in love.update or love.draw. Quad:setViewport exists if you want to change the Quad's information after creation.

A single 512x512 ImageData uses 1MB of RAM, and Lua's garbage collector can take a little while before freeing memory of objects in the "garbage", so it can balloon really fast if you create ImageDatas every frame, unless you explicitly call collectgarbage("collect").

Re: love.graphics.newQuad not so slow?

Posted: Sat May 04, 2013 6:24 pm
by bartbes
slime wrote:however as a rule of thumb you shouldn't call new* in love.update or love.draw
(unconditionally)
slime wrote: A single 512x512 ImageData uses 1MB of RAM, and Lua's garbage collector can take a little while before freeing memory of objects in the "garbage", so it can balloon really fast if you create ImageDatas every frame, unless you explicitly call collectgarbage("collect").
Let's not forget that creating an Image from it will upload it to your gpu, which is a relatively slow operation, and typically pauses any computations done on the gpu.

Re: love.graphics.newQuad not so slow?

Posted: Sat May 04, 2013 7:46 pm
by Ref
Thanks Slime & Bartbes!
Exactly the info I was looking for.
Really didn't know exactly what Quad:setViewport() did.
In this very limited case, using setViewport or newQuad doesn't seem to be frame rate limiting.