DocX icon indicating copy to clipboard operation
DocX copied to clipboard

Large Table building performance in v2.4

Open ghost opened this issue 2 years ago • 1 comments

Hello, I have been using this tool to generate large report documents (over 100 pages) that contain many large tables with data in them. This has worked until I recently attempted to upgrade from v2.3 to v2.4, and the time to generate these documents has dramatically increased to the point of rendering it unusable.

After investigating, I found that the time increases are all within rows that add the text to each cell, like this:

tbl.Rows[row].Cells[col].Paragraphs[0].Append(valueForCell);

If I remove or comment out these rows the document generation time is comparable to beforehand.

Looking at the changes since v2.3 in that function I see the new call to UpdateParagraphIndexesAndCurrentParagraphEndIndex:

public Paragraph Append( string text )
{
      var newRuns = HelperFunctions.FormatInput( text, null );
      this.Xml.Add( newRuns );

      _runs = this.Xml.Elements( XName.Get( "r", Document.w.NamespaceName ) ).Reverse().Take( newRuns.Count() ).ToList();

      this.UpdateParagraphIndexesAndCurrentParagraphEndIndex();
      return this;
}	

which in turn calls:

	this.Document.UpdateParagraphIndexes();

This new feature is not very performant when it comes to inserting data cell by cell into many larger tables. This appears to be already recognised somewhat as the Container function which has a way of internally disabling it via an internal member _preventUpdateParagraphIndexes:

internal void UpdateParagraphIndexes()
{
      if( this.Document._preventUpdateParagraphIndexes )
        return;

this internal member is used in a number of the ReplaceText methods to temporarily disable it.

Is there a way for us to disable this indexing feature temporarily ourselves until the entire table is built? If not, is this something that could be added in v2.5, as 2.4 is pretty much unusable at present?

ghost avatar Feb 27 '23 02:02 ghost

Hi,

thank you for your feedback. This is a known issue and a fix has already been implemented. It will be included in v2.5. It should improve your performance. Thank you.

XceedBoucherS avatar Feb 27 '23 12:02 XceedBoucherS