This is a migrated thread and some comments may be shown as answers.

Span has performance issues (?)

1 Answer 38 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Janos
Top achievements
Rank 1
Janos asked on 05 Dec 2011, 10:53 AM
Hello Telerik,

I experienced performance drop with RadRichTextBox, if a huge number of characters present in a single span and the user tries to delete some part of the text. I attached a sample code which loads a 'huge' string in RadRichTextBox. To be more specific i created a single Span inside the document and added a 20.000 length string.

MainPage.xaml:
<StackPanel x:Name="LayoutRoot" Background="White">
    <TextBox Name="textbox1" />
    <telerik:RadRichTextBox Name="radRichTextBox1" Height="500" BorderBrush="SlateBlue" BorderThickness="1" IsSpellCheckingEnabled="False" PreviewEditorKeyDown="radRichTextBox1_PreviewEditorKeyDown" CommandExecuted="radRichTextBox1_CommandExecuted" />
</StackPanel>

MainPage.xaml.cs
public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
        Init();
    }
    private DateTime startTime;
    // 32 characters
    private const string SAMPLETEXT = "sample text to fill richtextbox ";
    private void Init()
    {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < 625; i++)
        {
            stringBuilder.Append(SAMPLETEXT);
        }
        textbox1.Text = string.Format("Inital string lenght: {0}", stringBuilder.Length);
        // create span with sample text
        Span span = new Span() { Text = stringBuilder.ToString() };
          
        Paragraph paragraph = new Paragraph();
        paragraph.Children.Add(span);
          
        Section section = new Section();
        section.Children.Add(paragraph);
        RadDocument document = new RadDocument();
        document.Sections.Add(section);
        this.radRichTextBox1.Document = document;
    }
    private void radRichTextBox1_PreviewEditorKeyDown(object sender, PreviewEditorKeyEventArgs e)
    {
        if (e.Key == Key.Delete)
        {
            this.startTime = DateTime.Now;
        }
    }
    private void radRichTextBox1_CommandExecuted(object sender, CommandExecutedEventArgs e)
    {
        if (e.Command is DeleteCommand)
        {
            TimeSpan elapsedTime = DateTime.Now - startTime;
            this.textbox1.Text = string.Format("DeleteCommand executed in {0} ms", elapsedTime.TotalMilliseconds.ToString());
        }
    }
}


Reproduction scenario:
1. Open the sample application
2. Scroll down to the middle of the document
3. Select 4 or 5 lines inside the document
4. Press delete key.
5. Deletion takes relatively slow (~2 sec or more)

Is this really a performance issue? Is it a valid use case that the user will type 20000 character in a single line (without pressing 'enter')?

Best Regards,
Janos

1 Answer, 1 is accepted

Sort by
0
Ivailo Karamanolev
Telerik team
answered on 08 Dec 2011, 01:06 PM
Hello Janos,

With RadRichTextBox, as with all other controls, we are always trying to achieve maximum performance without sacrificing functionality. In order to achieve that, we carefully need to analyze the performance cases of our customers. RadRichTextBox is suited towards rich document editing, instead of general text editing. In rich text documents, the spans are usually small - they are broken by formatting, paragraph breaks, tables, etc. With these characteristics in mind, RadRichTextBox has a relatively good performance. 20K characters in a single Span is unlikely to occur, but in any case we are always working towards improving performance.
Let us know if you have a specific user scenario in mind, in which case we may be able to provide further assistance.

Regards,
Ivailo Karamanolev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Janos
Top achievements
Rank 1
Answers by
Ivailo Karamanolev
Telerik team
Share this question
or