WPF’s RTB is terribly slow when working with any realistic amount of text. And by realistic amount, I mean what you’d expect any text editor to be able to handle (100kb? At least) without showing any signs of slowness.
This expected RTB behavior is not the case for me. Actually, the control works pretty much like it should when text is neatly separated into small words and small paragraphs and I implement some mechanism that will zap my users’ whenever they get brave and type anything considerably long. I haven’t found a way to implement said mechanism yet, so instead I’m forced to (or at least attempt to) solve the problem.
I find this deeply disturbing because it makes no real sense to me. If you’re a daredevil and happen to type out one long string of characters without a space or break, you fall victim to a locked window for several seconds, making typing an unwelcome test of patience. What I’m anxious to know is: why is that? Specifically, why does it slow down more and more and only when text isn’t spaced consistently? Am I insane to consider the case that someone using my program will have a broken space bar and will thus be more inclined to notice this incredible slowdown? Text selection is also gravely affected in this contiguous-string case.
I’m targeting .NET 4.0, using VS 2010, and no events are hooked on the RTB; for testing purposes it’s nothing but a RTB (< RichTextBox />) on an empty window. What can I do to improve its performance? Is it more realistic to just write my own control for this, keeping the feature set to my minimum requirements? If so, any links to resources would be greatly appreciated.
It’s worth noting that the amount of data in the RichTextBox can be really small; what I was trying to make clear was that it’s the format of the text that really had the biggest impact on performance.
This is not an unusual problem for new implementations of text boxes. It has to do with the algorithm used for calculating line breaks. Based on the kind of behaviour you’re reporting, it sounds like the efficiency of the algorithm they use is strongly dependent on the length or words (i.e. it might be, say, O(n^2) with respect to the length of words). You should report this directly to Microsoft (with a clear example) so that they can fix the bug.