Page 1 of 1

Optimizing text drawing

Posted: Sun Jul 22, 2018 9:08 am
by molul
I'm making a frontend for a Rockchip RK3066 board, which apparently has a, say, "modest" GPU. A friend of mine is helping me with building LÖVE for this board (he's modifying SDL and other dependencies as needed), and I'm changing my LÖVE code to improve performance. So far we've managed to make the frontend run at 40-50fps (to give you an idea, it runs at 450fps on my Windows gaming laptop).

We currently have two bottlenecks: textures (I'm working on making spritebatches to improve this) and texts. Correct me if I'm wrong but texts seem to be drawn treating each character as a texture, which results in a very noticable slowdown when there the character amount displayed is high. Printing 50 characters is around 4-7fps slower than printing 5 characters.

I tried changing from using print of printf to display texts, to making a canvas and drawing the texts there, then drawing the canvas (less drawing calls). It got a little better, but eats too much GPU memory (I have around 200 different texts, and could have more) and the application is still very slow. So I tried drawing the canvas in runtime. Not bad, but switching texts quickly resulted in higher slowdowns. So I switched back to printing texts with print and printf again.

I wonder if there's anything we could do, either in LÖVE code or in SDL or any other dependency. My friend still wants to try to add triple buffer to SDL, but we're starting to run out of ideas. Any advice would be greatly appreciated :)

Re: Optimizing text drawing

Posted: Sun Jul 22, 2018 9:12 am
by Nixola
How are you printing stuff exactly? Could the bottleneck be in string manipulation rather than lg.print itself? Could using a Text object help? I'd help more but I'm afraid I don't have access to devices of similar power.

Re: Optimizing text drawing

Posted: Sun Jul 22, 2018 9:56 am
by molul
Thanks for replying :)

I'm mostly using love.graphics.printf, as I need to print texts (sometimes with more than one line) centered, and one of the texts (the currently selected option, displayed at the bottom of the UI) is constantly changing. So I think a Text object wouldn't help :(

It would be cool if Text objects had more features, like settin justification and wrapping.

EDIT: oh wait! I just noticed the :addf function. This might actually help. I'll investigate.

Re: Optimizing text drawing

Posted: Sun Jul 22, 2018 10:26 am
by pgimeno
For what I heard, Text objects are sort of spritebatches of text.

Re: Optimizing text drawing

Posted: Sun Jul 22, 2018 11:49 am
by raidho36
40 fps is not half bad for a device like this. Industry "standard" framerate is in single digits.

Try modifying the love.run function not to call the love.draw unless somewhere in love.update an appropriate flag is set. Don't update the screen either. Cut down on smooth animations to make use of this. Pro tip: people don't actually appreciate having to wait on animations to complete. They're cool to look at the first time, but it gets old fast - if you work with it every day you will hate it. Also try to cram as much data and controls on the same screen as possible - people positively hate navigating through dozens of screens to do simple things. If you have to split them, do extensive usage testing to figure out what's used together or in sequence - don't just split by category; don't make assumptions in general.

Re: Optimizing text drawing

Posted: Mon Jul 23, 2018 6:51 am
by molul
The problem is there are a few nice animations always running ^_^U Of course I'll cut them down if I can't reach 60fps but I'd rather not while there are other things to try.

I believe the sprite batches and text objects might give me 7-10 fps more, which would make the application run at 50-60. Hopefully triple buffer would give the last boost, and if not, I'll have to cut whatever is needed to.



EDIT: well, using drawable texts got me around 3fps more. Yay! :D I also found out I was always drawing a few objects out of the viewport, so I culled them and got another couple of fps. I'm currently on 47 to 60fps depending on the section, and I think the last LÖVE build my friend sent me is a bit slower due to constantly printing SDL debug messages on the console, so it might be 50-60 now. Let's see how spritebatches help ^^

EDIT2: spritebatches my ass. I only had to make texture atlases of all my textures and properly define quads ^_^U

Re: Optimizing text drawing

Posted: Mon Jul 23, 2018 9:51 am
by Nixola
molul wrote: Mon Jul 23, 2018 6:51 am EDIT2: spritebatches my ass. I only had to make texture atlases of all my textures and properly define quads ^_^U
If you're using LÖVE 11, that's probably because it automatically batches draw calls with the same texture

Re: Optimizing text drawing

Posted: Mon Jul 23, 2018 10:37 am
by molul
Yes, I'm using LÖVE 11, fortunately :) Using texture atlases and quads added another couple of frames. Not bad!