Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Nov 20, 2023 3:20 pm

Hello,

our client complains about performance when merging with compute. In the previous version they used it took 1-2 seconds per document, now it's 5-6 seconds. Usually they send several hundreds, even thousands of letters, which we prepare in advance (merge). In these cases, time is too much.

Here is my code:

Code: Select all
using (var document = new Document())
{
    document.LoadFromFile(template);
    document.SetCustomFontsFolders(Environment.GetFolderPath(Environment.SpecialFolder.Fonts));
    document.MailMerge.ClearFields = true;

    var resultFile = Path.GetTempFileName() + ".docx";

    document.MailMerge.Execute(dr);

    document.IsUpdateFields = true;

    document.ViewSetup.DocumentViewType = DocumentViewType.PrintLayout;
                   
    var sw = new Stopwatch();
    sw.Start();

    document.SaveToFile(resultFile);

    Console.WriteLine(sw.ElapsedMilliseconds);

    Process.Start(resultFile);
}


The most time consuming operation is SaveToFile.

My investigation shows that the performance issues were introduced in 7.9.0. In the previous version (7.8.4) the operation took ~1 second, starting from 7.9.0 it takes 5-6 seconds.

Regards

profiler007
 
Posts: 72
Joined: Wed Nov 13, 2019 11:32 am

Tue Nov 21, 2023 3:08 am

Hello,

Thank you for your inquiry.
Based on the information you provided, I simulated a Word document for preliminary testing and found that the program's runtime is approximately 1 second. I tested using the latest commercial version (Spire.Office Platinum(Hotfix) Version: 8.10.2). I suggest that you upgrade to this version for testing. If the issue still exist after testing, please provide the following information for further investigation. Thank you in advance.
1)Your input Word files, you can attach them here or send them to us via email (support@e-iceblue.com).
2)Application type, such as Console App, .NET Framework 4.8.
3)Your test environment, such as OS info (E.g. Windows 7, 64-bit).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Tue Nov 21, 2023 8:20 am

Hi,

You can find attached my test projects along with the template. Once opened, just need to "Restore nugget packages".

Tested on Windows 10. Execution time ~5-6 seconds.

P.S. When try to update to latest version (8.10.2) I got the following exception at runtime:

System.IO.FileLoadException: 'Could not load file or assembly 'Spire.Doc, Version=11.8.5.0, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)'

P.S. If you downgrade Spire to 7.8.4 the execution time is ~1 sec.

Spire.zip

profiler007
 
Posts: 72
Joined: Wed Nov 13, 2019 11:32 am

Tue Nov 21, 2023 10:01 am

Hello,

Thank you for providing the information.
I have tested the project you shared, and the program's runtime is approximately 1.4 seconds, which is significantly lower than the results you observed. I upgraded the Spire.Office version to 8.10.2 for testing, and the program's runtime was around 1.8 seconds. When I downgraded the Spire.Office version to 7.8.4 for testing, the program's runtime reduced to approximately 0.8 seconds.
I have attached the project with Spire.Office version 8.10.2 for you to download and test on your end. I look forward to receiving your feedback on the test results.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Wed Nov 22, 2023 8:29 am

Hi,

thanks for the quick reply!

I tested with your code and it's a bit faster. On my machine is slower compared to your - 2.8 sec vs 1.8 reported by you. I saw that you use Spire.Office for .NET, but we use Spire.Officefor.NETStandard where the results are even worst.

P.S. I still got the same exception when try to update Spire.Officefor.NETStandard to the latest version. I use Microsoft Visual Studio Enterprise 2022, version 17.8 (latest).

profiler007
 
Posts: 72
Joined: Wed Nov 13, 2019 11:32 am

Wed Nov 22, 2023 9:53 am

Hello,

Thank you for your feedback.
I have reproduced the issue you mentioned regarding the error occurring when using Spire.Officefor.NETStandard 8.10.2. I have already submitted this issue to our development team for investigation and resolution.
Regarding the performance issue, I conducted testing using Spire.Officefor.NET Standard 8.9.3, and the program's runtime was approximately 1.4 seconds. This is a significant difference compared to your test results. To further investigate the discrepancy, could you please provide me with the following information. Thank you in advance.
1) The amount of memory (RAM) available on your computer.
2) The regional settings of your computer(E.g. China, Chinese).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Thu Nov 23, 2023 10:00 am

Hello,

Thank you for your patience.
I am pleased to inform you that we have just released Spire.Office Platinum(Hotfix) Version:8.11.0, which addresses the error you previously mentioned. I have tested your project using this version, and the program now runs in approximately 1.5 seconds. Please upgrade to this version for testing purposes.
Website link:
https://www.e-iceblue.com/Download/download-office-for-net-now.html
Nuget link:
https://www.nuget.org/packages/Spire.Office/8.11.0
https://www.nuget.org/packages/Spire.Officefor.NETStandard/8.11.0

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Thu Nov 23, 2023 2:30 pm

Hi,

thanks for the quick reply!

I updated my test project to use the latest version and confirm that Spire.Doc loades correctly, no exception.

I retested on 3 different machines. You can find attached the results along with the machine configuration information and my test project.

What I noticed is that on 2 of the machines (workstations with CrowdStrike) the fragment executes for about 5-6 seconds. Both machines are more powerful than the third one, where the execution time is 1.5 seconds, like the time you observe. PC3 is without CrowdStrike or any antivirus software.

I believe most clients have some sort of antivirus software installed.

When I downgrade to 7.8.4 the results are comparable on all machines. The deference in the code is that I have to use SetCustomFontsFolders in the latest version, disperse I don't use any custom fonts. Maybe accessing the fonts folder is the real problem.

Can you investigated this and the difference between 7.8.4 and lattes versions where SetCustomFontsFolders is introduced.

Regards

profiler007
 
Posts: 72
Joined: Wed Nov 13, 2019 11:32 am

Fri Nov 24, 2023 7:47 am

Hi,

Thank you for your feedback and information on the test.
Due to our current inability to approve CrowdStrike trial applications, we are unable to conduct testing in an environment with CrowdStrike installed. I installed other antivirus software on my computer and tested your project, but the program's running speed was not affected. I have consulted our product manager and cannot determine if it was triggered by the CrowdStrike mechanism when writing files internally in our product. Please test the speed using the write file stream form to see if there is an impact. The sample code is below. This will help our development team investigate the cause of this issue. Thank you in advance.
Code: Select all
...
 MemoryStream stream = new MemoryStream();
 var sw = new Stopwatch();
 sw.Start();
 //document.SaveToFile(resultFile);
 document.SaveToStream(stream, FileFormat.Docx);

 sw.Stop();
 Console.WriteLine(sw.ElapsedMilliseconds);
 
stream.Position = 0;
 File.WriteAllBytes(resultFile, stream.ToArray());
 Process.Start(resultFile);
 Console.ReadKey();

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Fri Nov 24, 2023 8:17 am

Hello,

Thanks for the quick reply!

I tested with the suggested snippet and result it the same - ~5-6 sec per document. If I set document.IsUpdateFields to false it is 200-300ms, no matter if I use MemoryStream or not.

Btw, we tested with other antivirus program - Avast, same result.

Regards

profiler007
 
Posts: 72
Joined: Wed Nov 13, 2019 11:32 am

Fri Nov 24, 2023 10:04 am

Hello,

Thank you for your feedback.
I have installed the free version of Avast and restarted my computer to test again, but the program's running time remains around 1.6 seconds, as shown in the screenshot below.
AvastTest.png

Could you please provide the version number of the Avast you are using? This will facilitate our application for the corresponding version authorization and allow us to further investigate your issue.
Thank you again for your cooperation and understanding.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Fri Nov 24, 2023 2:35 pm

Hi, this is very strange.

23.10.6086 (build 23.10.8563) is the version my colleague has on his local machine.

Regards

profiler007
 
Posts: 72
Joined: Wed Nov 13, 2019 11:32 am

Mon Nov 27, 2023 7:43 am

Hello,

Thank you for providing the information.
I have installed the same version of Avast as you are using and tested the project you provided again. However, I noticed that the first time the program runs, it takes about 6.8 seconds, but subsequent runs take around 1.6 seconds. As you can see from the screenshot, the four runs of the program are timed. My computer's regional settings are set to China (Chinese). I have also tried setting my computer's regional settings to other languages, such as English in the United States, and found that the first run of the program takes about 5 seconds, but subsequent runs take around 1.4 seconds.
Could you please confirm if the "5-6 seconds" you mentioned refers to the first time the program runs? If that is the case, please note that the first run of a program can often be slower due to initialization and other initial processes. Subsequent runs usually become faster as the program enters a more stable and optimized state.
In addition, we suggest that you disable the antivirus software on your computer after installing it and then run the program again to see if there is any difference in the timing.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc