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.

Wed Oct 30, 2019 2:26 pm

We currently suffer from severe performance issues in our production environment.
After extensive debugging we found out that time spent in Garbage Collection was very high, especially when doing Document/Pdf related issues.

After doing some testing on the Spire.Doc code and decompiling the Spire.Doc libraries we found out that your library calls GC.WaitForPendingFinalizers and GC.Collect in the Dispose of Spire.Document. This has a severe impact on the performance of our application.

The offending code decompiled from ILSpy is:
Code: Select all
case 0:
      {
         ᝋ = true;
         \u1712();
         GC.WaitForPendingFinalizers();
         GC.Collect();
         short num = 0;
         num3 = num;
         goto default;
      }


I also found more occurences of GC.Collect calls in the code base (e.g. PdfDocument).
I would only have expected a GC.SuppressFinalize in the Dispose/Close (altough I'm not sure there is a finalizer in this class).

I made a very small test application to demonstrate the difference.

Code: Select all
            var sw = new Stopwatch();
            sw.Start();
            Parallel.For(1, 5000, (i) =>
            {
                using (var doc = new Spire.Doc.Document())
                {
                }
            });
            sw.Stop();
            Console.WriteLine(sw.Elapsed.TotalSeconds);
            sw.Reset();
            sw.Start();
            Parallel.For(1, 5000, (i) =>
            {
                var doc = new Spire.Doc.Document();
            });
            sw.Stop();
            Console.WriteLine(sw.Elapsed.TotalSeconds);


the version without the using (Dispose) is twice as fast, but imagine what this does in a much more complex application with much more objects in memory.

I also have a screenshot from the Visual Studio diagnostics tools from the code above, showing the massive amount of forced Garbage Collects.
Capture.PNG

During the second run only 1 collect is triggered, by the CLR itself (a GEN1 collection).

Moreover, GC.Collect forces ALL generations to be collected, never mind the WaitForPendingFinalizers.

We really would like to urge you to remove these GC.Collect calls from your library as this is very unexpected behaviour from a library class. Or if you are unwilling at least provide us the means to turn them off.

dinden
 
Posts: 16
Joined: Wed Aug 07, 2019 7:42 am

Thu Oct 31, 2019 10:20 am

Hi,

Thanks for your inquiry.
I have posted this issue to our Dev team for further investigation. Once there is any progress, we will inform you.
Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Mon Nov 04, 2019 8:29 am

As we did some further investigation, also the save to pdf does trigger a forced GC.Collect().
We have ways to work around not calling Dispose (or using a 'using'), but we cannot workaround saving to pdf, as this is the main reason we use the library.

Code: Select all
           for (int i = 0; i < 1000; i++)
            {
                var doc = new Spire.Doc.Document();
                var sect = doc.AddSection();
                var par = sect.AddParagraph();
                par.AppendText("bla");
                doc.SaveToFile("d:/temp/test.pdf", Spire.Doc.FileFormat.PDF);
            }

dinden
 
Posts: 16
Joined: Wed Aug 07, 2019 7:42 am

Mon Nov 04, 2019 10:34 am

Hi,

Thanks for your reply.
I have posted this new issue to our Dev team. We will consider removing the GC.Collect calls from our library in the future. Once there is any progress, we will inform you ASAP.
Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Mon Nov 18, 2019 9:17 am

Any updates or timeline on this?

dinden
 
Posts: 16
Joined: Wed Aug 07, 2019 7:42 am

Mon Nov 18, 2019 10:04 am

Hi,

Thanks for your reply.
I checked the state of your issue in our bug tracking system. Since the complexity of this issue, sorry that it has not been resolved yet. And sorry there is no ETA now. I have urged our Dev team. Once there is any progress, we will inform you ASAP. Apologies for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Dec 18, 2019 10:41 am

Hi,

Thanks for your patient waiting.
Glad to tell you that we just released Spire.Doc Pack(hot fix) Version:7.12.21 which optimizes the garbage disposal. Welcome to download it from the following links.
Our website link: https://www.e-iceblue.com/Download/download-word-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.Doc/7.12.21

Sincerely,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Dec 25, 2019 9:53 am

Hi,

Greetings from E-iceblue.
Have you tried Spire.Doc Pack(hot fix) Version:7.12.21? Does it solve your issue?
Could you please give us some feedback at your convenience?

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Mon Jan 06, 2020 12:30 pm

Amber.Gu wrote:Hi,

Greetings from E-iceblue.
Have you tried Spire.Doc Pack(hot fix) Version:7.12.21? Does it solve your issue?
Could you please give us some feedback at your convenience?

Best wishes,
Amber
E-iceblue support team


We are upgrading ATM, will take some time before it lands in production.
My test project already shows that there are no more forced Garbage Collections happening, so that looks good.

dinden
 
Posts: 16
Joined: Wed Aug 07, 2019 7:42 am

Tue Jan 07, 2020 1:19 am

Hi,

Thanks for your feedback.
If there is any question, welcome to contact us. Have a nice day.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.Doc