UpdateFields() Slower in Version 9.6

UpdateFields() has two different speeds at which it operates in my project depending on which version of Aspose.Words for .NET I use. If I use version 9.5, my test document is generated in ~45 seconds. However, when using version 9.6 it takes about 2 minutes and 45 seconds. Did the internal changes made for 9.6 make that much of a difference? Any ideas?

Back ground: I have three table of contents (TOC) that must be populated in my document. In order to populate each one correctly, they are individually updated. Each one is in its own section. A list of the TOC section indexes in the variable tocSectionIndices. The basic code snippet is:

// Populate Table of Contents
foreach(int tocSectionIndex in tocSectionIndices)
{
    doc.Sections[tocSectionIndex].Range.UpdateFields();
}

// Update page numbering of document
doc.UpdatePageLayout();

I found out that it was UpdateFields() by stepping through my code in the debugger. Executing the above code snippet is where my program slowed down.

Thanks!

Hello

Thanks for your request. Starting from Aspose.Words 9.6 the way that some fields are updated is slightly different, due to internal reworking of the field evaluation engine. Please see the following link to get detailed explanation:
https://docs.aspose.com/words/net/update-fields/
Best regards,

Thank you for the reference. I have read the article, but did not find anything dealing with the variations in speed of Aspose.Words for .NET. Did I miss something?

Maybe my situation is unique? Based
on code that was created with Aspose’s help (please see message number
282898 in reply to 282815) I need to call UpdateFields() and UpdatePageLayout (). Based on that information, any ideas please?

Thank you.

Hi Rob,
Thanks for your inquiry.
It’s hard to say what’s causing this slowdown. The only thing that I could think of is if you are inserting many fields manually. These are also now updated on the spot when they are inserted without a field result.
Perhaps try updating all fields in the document first and then updating each section after that.
If this does not help could you please create a sample project that reproduces the issue. I will take a closer look into the issue.
Thanks,

When stepping through the code the spot that requires the most cpu cycles is doc.Sections[tocSectionIndex].Range.UpdateFields(). The amount of cpu cycles is much greater when using 9.6 than 9.5. I created a break point there and timed it both versions. For testing purposes, I excluded the manual extraction, sorting, and re-entry of the fields so to have a base test to work from. So I think we can rule the updating on the spot.

When you say: “…try updating all fields in the document first and then updating each section after that” do you mean to do it as below?

doc.UpdateFields();

// Populate Table of Contents
foreach(int tocSectionIndex in tocSectionIndices)
{
    doc.Sections[tocSectionIndex].Range.UpdateFields();
}

// Update page numbering of document
doc.UpdatePageLayout();

Based on your response, I’ll move forward with creating a sample project. Basically it would be the same as I have created before with my TOC issues, but with several hundred fold more heading enteries. (Aka more data that would have to be inserted into one of the three TOC 's)

Thanks!

Hi Rob,
Thanks for this additional information.
Yes that’s exactly what I meant. Have you tried it? Did it make any difference to the update speed? I think perhaps updating each section separately would be only be partially rebuilding layout, which together would be slower than updating all fields at once. I am not fully sure of this though.
I will wait for your sample project.
Thanks,

Yes, by adding UpdateFields() first and eliminating the processing of each TOC seperately as improved performance. In message 274972, I did not understand that the processing of each section was not necessary. Removing “\u” was all that was needed.

I created a test project which is attached. (For those that read this post, but can’t see the attachment it is a copy of my test code in message 280325. Just repeat one of the header write lines several 1000 times. aka builder1.Writeln(“Heading 3.1.3.3”);) I tested it with both the 9.5 and 9.6 Aspose.Words for .NET dll’s.

This test case does not take as long a with my actual project, but will allow you to see that there is a significant difference in processing time between 9.5 and 9.6.

Please let me know your findings and any suggestions.

Thanks.

Hi Rob,
Thanks for attaching your sample project here. You’re correct that a single update of a large document takes a little longer in 9.6 than in 9.5 (around 40% more). This is normal because the changes to the field engine allows more accurate update but at the same time may result in a bit of a slower field update.
In any case, I thought the issue you wanted me to check was the speed regarding updating separate sections in a document but the sample code did not do anything like that. Is speed still an issue after the suggestion of updating all fields at once?
Thanks,

No, it was just the overall performance of Aspose.Words that I needed addressed. Sadly speed is an issue. The increased accuracy of the engine is great, but the speed penalty is killer. The size documents that we render are quite large, so we have almost tripled the time needed. For example, it took ~45 seconds. However, when using version 9.6 it takes about 2 minutes
and 45 seconds. That is not good for our end user…

Any ideas if you will be able to regain any part of the lost performance soon. If not I think I will need to go back and try and get version 9.5 to work with my code.

Thanks.

Hi Rob,
Thanks for this additional information. I will make some inquiries with the developer responsible for field update and provide you with some further feedback.
Thanks,

Thank you.

Hi Rob,
Actually taking another look at my code, I noticed I forgot to call UpdatePageLayout when testing the older versions. After correcting this, it made the times taken to update in both versions almost the same. I then tried using your situation from your other thread (sorting TOC entries and repopulating them) but again both updated with very similar times.
Are you able to attach another sample project which demonstrates the slow down you are experiencing? Perhaps there is an external factor affecting the times for the 9.7 version?
Thanks,

aske012:
Actually taking another look at my code, I noticed I forgot to call UpdatePageLayout when testing the older versions.

Where did you add this in the code, please? That way I can verify this on my end.

Thanks.

Hi Rob,
I used the simplified code below for testing. The call to UpdatePageLayout is removed when testing the 9.7 version of the code. Using this code both versions take around the same time to update fields. I tested your other situation where you repopulate a TOC and then update and both versions complete that in around the same time as well.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertTableOfContents("\\t \"Heading 1,1\"");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
for (int i = 0; i <2500; i++)
{
    builder.Writeln("Heading 1");
}
Stopwatch timer = new Stopwatch();
timer.Start();
doc.UpdateFields();
doc.UpdatePageLayout();
timer.Stop();
Console.WriteLine("Time taken: " + timer.Elapsed.TotalSeconds);

Thanks,

Hi,

When did version 9.7 come into the equation? My problem is with the difference between versions 9.5 and 9.6. Just curious because we had been discussing the performance issue between those two versions and now you start mentioning version 9.7. Please let me know.

Thank you very much.

Hi
Thanks for your request. 9.7.0 was a maintains release. It does not contain any fixes or changes that can affect performance. So I suppose you will get the same result if you compare 9.5 and 9.6.
As it was already mentioned starting from 9.6 version it is not required to call UpdatePageLayout to update numbers in TOC. Now UpdateFields does this all together. That is why if compare performance of UpdateFields in 9.5 and 9.6 versions you will see that 9.5 is faster. However, if you run UpdateFields+UpdatePagelayout in 9.5 version it will take the same time as running UpdateFields in 9.6.
Best regards,

aske012:
The call to UpdatePageLayout is removed when testing the 9.7 version of the code.

Okay, but the code we worked out between you and me included the need to call UpdatePageLayout(). (Please see message # 282898.) That is because of my situation with the three different TOC’s (each in their own section). So what can we do? Can the sample project you included in message # 285506 account for that?

Thanks!

-Rob

Hi Rob,
Thanks for your inquiry.
Yes in my previous message I also described that I have tried with your unique code and it to executed in around the same time. This makes sense as both versions need the extra UpdatePageLayout call and both need to rebuild page layout which takes around the same time.
Are you able to double check on your side and perhaps try again to create a sample project?
Also as Alexey stated there is no difference in update speed between 9.6 and 9.7.
Thanks.

Hi Guys,

I ran your sample code on my side. I got a difference in time between version 9.5 and 9.6. The average of three runs is my elapsed total seconds:

  • Version 9.5: 4.97
  • Version 9.6: 6.03 (Without UpdatePageLayout())
  • Version 9.6: 7.67 (With UpdatePageLayout())

I am not sure how you guys get the same time elapsed from both versions. Maybe we are running different hardware and OS? I’m running XP Pro 64 bit, using Visual Studio 2008, on Xeon processor at 3.33 Ghz. Any ideas? Did something change from your tests with my sample code from message # 284720? (There you stated it is about 40% difference in speed b/t versions.)

Thank you.

-Rob

Hi Rob,
Thanks for this additional information.
I have tested again using the sample code from your other thread. Both versions finish within 1.5-2 seconds. Perhaps you are using a more complex document? Are you able to attach it here?
I can’t find any reason based off your computer specs as to why there would be a slow down between versions. Are you sure you are running in Release mode with both versions?
The only difference between the tests in message 284720 is that I forgot to call UpdatePageLayout. It wouldn’t make sense to not call UpdatePageLayout as you would be left with TOCs with no page numbers.
Since I can’t reproduce the issue on my side I will need a sample project which demonstrates the issue to invesigate further.
Thanks,