Also, while playing with the TextEditor, I got some strange numbers, performance-wise.
I am trying to use a read-only TextEditor as a text output console, repeatedly calling TextEditor::insertTexAtCursor().
When adding more than a thousand lines, things start getting very expensive and unbearably slow.
A little bit of profiling showed that the undo manager gets very busy while inserting lines. Disabling when in read-only mode improved things.
I noticed that 90% of the cpu time spent in TextEditor::insert is sucked up by moveCursorTo (which tries to reposition the viewport to make the cursor visible, and therefore recomputes a lot of text metrics).
Yes, I’ve never optimised it for really large amounts of text. But it does go massively faster in release mode than debug, because there’s a huge number of assertions in there, so try a release build before you spend too long worrying about its performance!
But thinking about what you found there, I’ve just checked in a couple of quick and simple optimisations that might make a big difference - give it a try…
You’re doing 10000 inserts programatically?? That’s nuts! No wonder it’s messing up - better to create your string beforehand and insert it in a single operation, of course.
I’m still a bit surprised that it’d break the message queue though - any idea which bit of it is responsible for that?
Trouble is, the TextEditor is used like a console output, and I have no way of predicting what console writers will do with it. I guess a Timer and some buffering will help.
I’ll take a closer look at the message queue breaking and let you know.
Ah, I see - that’s a pretty reasonable use for it! But it’ll never be very quick to insert text, because of all the undo/redo stuff that’s required, so you’re better off batching the insertions together if possible.
textColourId = 0x1000201, /**< The colour that will be used when text is added to the editor. Note
that because the editor can contain multiple colours, calling this
method won't change the colour of existing text - to do that, call
applyFontToAllText() after calling this method.*/
This doesn’t hold true anymore. And I am relying on it…