Free Support Forum -

Table.Clone method is very time-consuming

We bought Aspose.Words to recode our former Word-based doc generation engine from scratch.
The engine needs a doc template and an xml file to produce the final doc.
The presentation code is in the template along with field markers - basically loops and datas.
The xml file contains the sql queries to get the data from the datastore and the instructions to replace the field markers with the real data.
As we have many customers using the former version, we cannot change the way the engine works - same inputs, same outputs.
We just want to replace MsWord by Aspose.Words to write the doc.

After a lot of tries, we always encounter a performance issue when dealing with the tables.
We used a profiler and discovered that the clone method on a table is very time-consuming (about 2s in average based on 150 calls) even if the table contains only one row with three or four cells.

Do you have any tip about this ?

Are you sure that it is Clone function that slows things down? The similar problem was discussed here:

and we came to a conclusion that it was indexed access which became slow with growing number of the rows. It is also significantly slower for the first indexed access attempt after the number of the rows is changed. InsertAfter is also working slower than AppendChild or Add function.

So the final recomendation was to build table first in one loop and fill the data in another.

Check if it helps. If not we will consider the matter further. We can even try to optimize it specifically for the tasks like yours in the future version. You will need to provide the complete use case (test project) to start this activity.

Best regards,

I attached screenshots from the profiler project, where it shows that :
- the total execution time is : 398s (see aspose2.png)
- the total time spent in the table.clone method is : 326s for 130 hits (see aspose1.png)

We’re also considering to use the mailmerge functions as our first tests revealed very fast doc generations.
However we’re not sure to be able to automatically convert our former templates to the structure understood by the mailmerge functions. For instance, our template have nested loops and do not use mail merge fields.

Have anyone encoutered similar difficulties? Any tip is welcome.

Best Regards

Please attach the snippets of the code and those templates you have spoken of. I will try to find out if any optimization for the code and adaptation for the templates is possible.

Best regards,