GML Most efficient way to render a textbox

sv3nxd

Member
Hey,
I'm currently working on an open-source project in which you can create a textbox with one single command.
I've been working on it for a long time now, trying to improve it in every way I could.
(https://github.com/Sven98/ezBox)

I was wondering if the way I am doing it right now is efficient or not.

Let me walk you through:

-> We create a surface
-> We take an input and generate a list of words
-> We generate a formatted string with the given words
-> Every counter-tick we add a letter of a word to our surface
-> We draw the surface

Performance

Without any rendering happening I average ~22.000 FPS
With the textbox open I average ~11.000 FPS

That's a loss of 50%. I tried it on my laptop, which is not as high-end and the percentage is the same.
Is that an acceptable rate of performance-loss? Is it too much?

Code

This code executes every counter-tick

upload_2020-2-22_17-1-14.png

Is there anything you would change? Would you use something other than surfaces?

Thanks for your time!
 

Simon Gust

Member
22000 fps to 11000fps being a loss of 50% performance is incomparable, it is an increase of 50% milliseconds per frame.
If your game finishes a frame in 0.045 ms, it will take 0.090 ms with the textbox now. You have to work with absolutes, if you add another textbox,
your fps won't be another 50% lower as in 5500 fps (0.180 ms) it will be 7400 fps (0.135) based on raw calculation.
at 16.6667 ms your game runs at just 60 fps so you can work out that adding this textbox did nothing.

And on weaker devices, say an old laptop which ran at 1500 fps without any rendering. it is only 0.62 ms slower. That is nothing. And you can't exactly judge how it will behave with more stress.
 

sv3nxd

Member
22000 fps to 11000fps being a loss of 50% performance is incomparable, it is an increase of 50% milliseconds per frame.
If your game finishes a frame in 0.045 ms, it will take 0.090 ms with the textbox now. You have to work with absolutes, if you add another textbox,
your fps won't be another 50% lower as in 5500 fps (0.180 ms) it will be 7400 fps (0.135) based on raw calculation.
at 16.6667 ms your game runs at just 60 fps so you can work out that adding this textbox did nothing.

And on weaker devices, say an old laptop which ran at 1500 fps without any rendering. it is only 0.62 ms slower. That is nothing. And you can't exactly judge how it will behave with more stress.
That does make sense. What would be the best way to test if something is actually performance-heavy or not in your opinion?
 

sv3nxd

Member
You can do that by running the profiler in your debugger.
https://docs2.yoyogames.com/source/_build/2_interface/2_extras/debugging.html
If you tick "average values" you can exactly see which part takes how many milliseconds each frame.
Thank you for that! That was extremely interesting.
I never knew such a feature existed in GM's Debugger.

So the textbox takes 0.50ms, 0.22ms in the step-event and 0.28ms in the draw-event. But contrary to what I thought, it's not the drawing of the surface which is the most time-consuming (which in retroperspective does make sense), but actually my "debug mode" that drew the padding, the lowest fps and other variables. More so, using "string()" twice was 0.12ms on it's own, crazy!

With those deactivated the draw-event only takes up 0.003ms. (Without drawing background, border or corner-tiles of course).

upload_2020-2-23_12-40-2.png

That was really interesting and gives me a whole new perspective to improving code. Thank you very much.

Take a look at how fc dialogue works it's pretty similar concept.

https://marketplace.yoyogames.com/assets/6076/fc-s-dialogue-system
Oh yea! I saw that one. It's so well made it makes me mad, haha.
Sadly I saw it way late when already having started, so now I'll see mine through anyways.
 
Top