Table Performance issue

Hi,

I need to create a document with high numbers of table rows and then convert it to PDF. The issue I am facing here is performance time and memory consumption while converting to pdf for such document.

Time taken to convert 250 rows : 427
Time taken to convert 500 rows : 475
Time taken to convert 1000 rows : 622
Time taken to convert 5000 rows : 2587
Time taken to convert 10000 rows : 4615

This is just a word to pdf conversion time. You can add word creation time on top of it. Please let me know how can we improve performance in this scenario.
Is there any specific way we should create the document so that it will give me better performance?

Hi Sharon,

Thanks for your inquiry. Please note that performance and memory usage all depend on complexity
and size of the documents you are generating. While rendering a document to fixed page formats (e.g. PDF), Aspose.Words needs to build two model in the memory – one for document and the other for rendered document.

Usually,
Aspose.Words needs 10 times more memory than the original document size
to build it’s DOM in the memory and when it comes to rendering a
document to fixed page formats (e.g. PDF).

It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word document.
  • Please

create a standalone/runnable simple Java application that demonstrates the code (Aspose.Words code) you used to generate
your output document

As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

public class AsposeLoadTest {

    public static void main(String[] args) {
        try {
            testConvert(250);
            testConvert(250);
            testConvert(500);
            testConvert(1000);
            testConvert(5000);
            testConvert(10000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void testConvert(int count) throws Exception {
        long time = System.currentTimeMillis();
        FileInputStream fis = new FileInputStream(new File("/users/akundu/data/table_data_" + count + ".docx"));
        Document doc = new Document(fis);
        OutputStream outstream = new ByteArrayOutputStream();
        PdfSaveOptions opt = new PdfSaveOptions();
        opt.getOutlineOptions().setDefaultBookmarksOutlineLevel(9);
        doc.save(outstream, opt);
        System.out.println("Time taken to convert " + count + " rows : " + (System.currentTimeMillis()-time));
    }
}

Hi Sharon,

Thanks for sharing the detail. I have tested the scenario using latest version of Aspose.Words for Java 14.11.0 and have not found the performance issue. I have used the following method to create the table and export final document to Pdf.

private static void testConvert(int count) throws Exception {
    long time = System.currentTimeMillis();
    // FileInputStream fis = new FileInputStream(new File(MyDir + "table_data_" + count + ".docx"));
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.startTable();
    for (int i = 0; i < count; i++) {
        builder.insertCell();
        builder.write("Row 1, Cell 1 Content.");
        // Build the second cell
        builder.insertCell();
        builder.write("Row 1, Cell 2 Content.");
        // Call the following method to end the row and start a new row.
        builder.endRow();
    }
    builder.endTable();
    OutputStream outstream = new ByteArrayOutputStream();
    PdfSaveOptions opt = new PdfSaveOptions();
    opt.getOutlineOptions().setDefaultBookmarksOutlineLevel(9);
    doc.save(outstream, opt);
    System.out.println("Time taken to convert " + count + " rows : " + (System.currentTimeMillis()-time));
}

It is quite difficult to answer such
questions because performance and memory usage all depend on complexity
and size of the documents you are generating. While rendering a document to fixed page formats (e.g. PDF), Aspose.Words needs to build two model in the memory – one for document and the other for rendered document.

Please note that the process of building layout model is
not linear; it may take a minute to render one page and may take a few
seconds to render 100 pages. Also, Aspose.Words has to create APS (Aspose Page Specification)
model in memory and this may again eat some more time for some
documents. Rest assured, we’re always working on improving performance;
but, rendering will be always running slower than simple saving to flow
formats (e.g doc/docx).