Performance Issue with UpdateFields() in Large Word Bundle Processing

Hi team,

We are experiencing serious performance bottlenecks when using UpdateFields() in Aspose.Words during the process of concatenating multiple file formats (images, PDFs, plain text, emails .eml, .msg) into a Word bundle document. Additionally, we have a custom page numbering system (custom header/footer) that depends on user settings and templates.

Problem Details:

The final generated word bundle is approximately 700 MB, which was concatenated from 250 files (PDF, image/*, eml, …), and was created locally.

Version: 24.4.0

  1. UpdateFields() takes approximately 40 minutes to complete.
  2. The operation consumes high RAM usage on the server, significantly impacting performance.

Here is an example code:

// Insert Table of Contents using Heading8 & Heading9
templateBuilder.InsertTableOfContents("\\o \"8-9\" \\h \\z \\u");

// Set TOC Styles
templateBuilder.Document.Styles[StyleIdentifier.Toc8].Font.Size = 16;
templateBuilder.Document.Styles[StyleIdentifier.Toc8].Font.Name = "Arial";
templateBuilder.Document.Styles[StyleIdentifier.Toc9].Font.Name = "Arial";


public void AddHeading8(DocumentBuilder builder, string text)
{
    builder.Font.ClearFormatting();
    builder.ParagraphFormat.ClearFormatting();
    // Specify font formatting before adding text.
    var font = builder.Font;
    font.Size = 32;
    font.Bold = true;
    font.Color = System.Drawing.Color.Blue;
    font.Name = "Arial";

    builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading8;
    builder.Writeln(text);

    builder.Font.ClearFormatting();
    builder.ParagraphFormat.ClearFormatting();
}

public void AddHeading9(DocumentBuilder builder, string text)
{
    builder.Font.ClearFormatting();
    builder.ParagraphFormat.ClearFormatting();
    var font = builder.Font;
    font.Bold = true;
    font.Color = System.Drawing.Color.White; //Work around solution to cheat end user
    font.Size = 1;
    font.Underline = Underline.None;
    font.Name = "Arial";
    builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading9;
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
    builder.Writeln(fullText);

    builder.Font.ClearFormatting();
    builder.ParagraphFormat.ClearFormatting();
}

Could you guys help to check and provide solutions?

@threadsoftware I am afraid, there is no general solution. It looks like your document is simply too large. To update TOC, it is required to build document layout, which is quite time and resource consuming operation. The following article might answer some questions regarding memory consumption:
https://docs.aspose.com/words/net/memory-requirements/

I can only suggest to avoid using such large documents and use several smaller documents instead. I suspect even MS Word is struggling to process 750MB document.