Trying to get efficient text printing in Rust + resizing issues


#1

So, I’m learning how to create a text editor, and I’m using Rust for that. I don’t think it’ll grow to be an actual editor in the future, but I wanted to do it in a fast language. I am trying to use Piston as far as possible and until now I got everything I needed. I’m even creating the components myself (I’m not using conrod).

The code itself is hosted at https://github.com/Razican/Editor

I’m using Text::draw() to draw the text, as you can see here: https://github.com/Razican/Editor/blob/master/src/main.rs#L126. For a small text file I’m getting really low frame rates. Of course the buffer is still not optimized, but the main problem gets when rendering the text. The CPU gets really hot, in fact, so it’s doing everything it can.

What could it be? can it be improved?

And about resizing, if you try it out, you’ll see how the text gets smaller if you make the window bigger. Why could that be?

Thanks in advance for the help! :slight_smile:


#2

While Rust is a fast language, third-party libraries are not necessarily fast.
Piston’s rendering system draws sprites one by one instead of batching them, so you can’t expect to draw more than 1000 to 2000 sprites per frame if you still want to run at 60 frames per second.


#3

Hmmm that is probably a problem. What could I do to print more characters per each loop? Maybe I can combine the characters in an only sprite? but is Piston able to do that? should I use other libraries?