We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Performance of Range.replace(String, String, FindReplaceOptions)


I have noticed a decrease in performance from version 18.2 to 18.3 using method Range.replace(String, String, FindReplaceOptions).
The performance issue is still contained in version 18.8.
The performance issue is probably caused by ticket WORDSNET-14725.

This performance issue occurs when a content control contains CustomXml.
I have investigated the performance issue on two different documents. The first document contains a content control with CustomXml. The second document contains a content control without CustomXml.
There are always two identical paragraphs, because I have noticed a difference in performance between the first and second method call.

Test setup:
replace.zip (51.6 KB)

doc = new Document("replace_<option>.docx");
Range range1 = doc.getFirstSection().getBody().getChild(NodeType.PARAGRAPH, 0, true).getRange();
Range range2 = doc.getFirstSection().getBody().getChild(NodeType.PARAGRAPH, 1, true).getRange();

long timeFirstLineStart = System.nanoTime();
range1.replace("test", "test2", new FindReplaceOptions());
long timeFirstLineEnd = System.nanoTime();
System.err.println("Time to replace first line: " + (timeFirstLineEnd - timeFirstLineStart) + " nanoseconds");

long timeSecondLineStart = System.nanoTime();
range2.replace("test", "test2", new FindReplaceOptions());
long timeSecondLineEnd = System.nanoTime();
System.err.println("Time to replace second line: " + (timeSecondLineEnd - timeSecondLineStart) + " nanoseconds");

My test results:

document with CustomXml
first paragraph
version 18.2 = ~6ms
version 18.3 = ~90ms
second paragraph
version 18.2 = ~0,6ms
version 18.3 = ~2ms

document without CustomXml
first paragraph
version 18.2 = ~6ms
version 18.3 = ~6ms
second paragraph
version 18.2 = ~0,6ms
version 18.3 = ~0,6ms

If the content control contains CustomXml, the performance with version 18.3 is significantly slower.
Why has performance decreased so much between the versions?

Ingo Gutzeit


Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17337. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Thank you very much for your effort.

Ingo Gutzeit


Thanks for your patience. We have improved the performance of Range.Replace method in the latest version of Aspose.Words for Java 18.11. Please try it. Hope this helps you.

The issues you have found earlier (filed as WORDSNET-17337) have been fixed in this Aspose.Words for .NET 19.12 update and this Aspose.Words for Java 19.12 update.