none
Tables with many lines slow as ____

    Question

  • Hi

    Sorry for the title but I am quite annoyed at the moment. We have deployed an application at a customer and now performance issued have arrived. We are using a Table in WPF in conjunction with a FlowDocument. Now when adding Data to this table it takes an eternity to build the table. We do have some 5000 rows, each containing about 10 cells. All of them contain text only (although it might be formatted as currency or it might be aligned left or right).

    I was able to write a short piece of code that shows the problem:

    Debug.WriteLine("Building virtual table");
    
    Table tx = new Table();
    tx.RowGroups.Add(new TableRowGroup());
    
    for (int i = 0; i < 5000; i++)
    {
    	TableRow tr = new TableRow();                
    	tx.RowGroups[0].Rows.Add(tr);
    
    	for (int j = 0; j < 20; j++)
    	{
    		tr.Cells.Add(new TableCell(new Paragraph(new Run("Blaaa"))));
    	}
    
    }
    Debug.WriteLine("Done building virtual table");

    This process takes MINUTES to complete. I suppose that the problem lies in the fact that you have to create all these new objects.

    For my actual question: Is there a faster way to do this or how could I resolve this issue?

    Thanks for any help

    Thomas

    Thursday, April 01, 2010 4:30 PM

Answers

  • Hi Thomas Li,

    You can try to optimize the code as follows, it will be much faster:

    Table tx = new Table();

    TableRowGroup towgroup = new TableRowGroup();

    for (int i = 0; i < 5000; i++)

    {

        TableRow tr = new TableRow();

        towgroup.Rows.Add(tr);

     

        for (int j = 0; j < 20; j++)

        {

            tr.Cells.Add(new TableCell(new Paragraph(new Run("Blaaa"))));

        }

    }

    tx.RowGroups.Add(towgroup);

    Hope this helps.

    Best regards,
    Linda Liu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Linda Liu Thursday, April 08, 2010 4:41 AM
    Monday, April 05, 2010 1:48 PM

All replies

  • I should also mention that displaying performance is acceptable after the table was build - a little slow but still usable.

    I was wondering if there was another way how to do this in WPF. It should suffice if the whole table is a single textblock - but how do I format the columns to "look like" columns?

    Thursday, April 01, 2010 5:21 PM
  • Your issue is that it makes no sense instantiating and rendering 50,000 text displaying objects in any human used application.

    Google "WPF data virtualization" and you'll find a lot of useful information.


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Thursday, April 01, 2010 5:21 PM
  • Hi Bigsby

    Thank you for your response. I fully agree that it makes no response having so much data (the data isn't interesting anyway). Yet, the customer obviously has a strong need for this. I was especially happy about the features the FlowDocument gives me (displaying data IN the application, simple printing, ...). Thank you for the Keyword Data Virtualization - I'm pretty sure I will use that in future projects when possible.

    Yet, I cannot use it here since I also have to support printing and therefore I need the flow document as well. I find it hard to believe that there is no way to create a table in a less complex way.

    Friday, April 02, 2010 6:57 AM
  • Hi Thomas Li,

    You can try to optimize the code as follows, it will be much faster:

    Table tx = new Table();

    TableRowGroup towgroup = new TableRowGroup();

    for (int i = 0; i < 5000; i++)

    {

        TableRow tr = new TableRow();

        towgroup.Rows.Add(tr);

     

        for (int j = 0; j < 20; j++)

        {

            tr.Cells.Add(new TableCell(new Paragraph(new Run("Blaaa"))));

        }

    }

    tx.RowGroups.Add(towgroup);

    Hope this helps.

    Best regards,
    Linda Liu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Linda Liu Thursday, April 08, 2010 4:41 AM
    Monday, April 05, 2010 1:48 PM