title: Performance Flowdocument with Table with a big amount of data
body: <p>What I try to do:<br>
  Generate a report based on data from the database, and then be able to view it and print it. (This in WPF C#)</p>
  
  <p>How I do it: (dynamically, via code)<br />
  My Window is simple, it's just a FlowDocumentPageViewer with nothing in it.<br /></p>
  
  <ol>
  <li>I load the data from the database<br /></li>
  <li>Use LINQ to group it all properly<br /></li>
  <li>Initialize a new Flowdocument<br /></li>
  <li>Make a Table, with a RowGroup<br /></li>
  <li>Loop my LINQed data and fill the RowGroup with TableRows that contain cells with the required data<br /></li>
  <li>Add the Table to the Flowdocument</li>
  </ol>
  
  <p>And this pretty much works fine, except when the amount of records goes to 10k. Then for some reason it just sucks up my CPU to 25% and takes 30 minutes. Scrolling is also pretty much impossible, not a thing happens, it just totally jams.
  But when I got 1k records, it takes 18 seconds. And with 2k, its 74 seconds.</p>
  
  <p>I do however, do not use the standard way of cells in Tables, I have to make a TextBlock for  each cell, and use that with a BlockUIContainer. But after some testing it didn't seem to have much of an impact in generating the document.</p>
  
  <p>Anyone with tips on stuff that I should worry about? Would be a major help, I'm hitting a brick wall here.</p>
  
  <p>I thought about maybe a way that it only renders the current page, but I can't know how many pages there will be with a FlowDocument.</p>
  
  <p>The type of data I use is just strings, and sometimes checkboxes (readonly).</p>
  
  <p>Edit:<br />
  The time to process it seems very steady, with 1 second as margin. But exponential, with 3k it's already at 164 seconds.</p>
  
  <p>Edit2:<br />
  After some more testing, I found out that <b>the</b> problem is when I add a TableCell to the TableRow. Without that, it only takes 1.6 seconds.</p>