PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jun 15, 2024 8:22 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 21 posts ] 
Author Message
PostPosted: Fri Jan 19, 2007 8:10 am 
Offline

Joined: Fri Jan 19, 2007 7:16 am
Posts: 1
I have a Question about the time to render large tables.
I have modified the "invoice" example from MigraDoc-Lite and add some more columns to the table (all together 17). Then I wrote a loop to add 500 rows of (dummy) content to the table.
The renderer now needs about 10 Minutes to render the File. Is it possible to reduce this timespan?

Thanks for Help!

J. Sticksel


Last edited by JSticksel on Mon Aug 20, 2007 8:39 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 19, 2007 9:39 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Table rendering is a bit slow, but we haven't investigated that problem yet.
I think we can speed it up quite a bit, but I'm afraid we won't have time for that in Q1/2007.

Processing time is OK on my 3 GHz workplace computer, but is a pain on our 500 MHz test computer.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 07, 2007 2:11 pm 
Offline

Joined: Mon Feb 05, 2007 8:12 pm
Posts: 3
Noticed this problem. Hope that the rendering will be improven, my whole application is based on tables (pdfsharp is only used for generating reports...)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 08, 2007 11:24 pm 
Offline
empira Employee
User avatar

Joined: Thu Oct 12, 2006 10:07 pm
Posts: 49
Location: Cologne, Germany
Yes, the performance of rendering tables is extreamly lousy.
One problem is that creating a font is an expensive operation. The Invoice sample create 1800 times an XFont, Hello MigraDoc over 7200 times, and even Hello World creates 14 times a new font. This is not acceptable. I put it on the bug list. We will release an update immediately when we have fixed it.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Mar 24, 2007 5:35 pm 
Offline

Joined: Fri Mar 23, 2007 11:37 pm
Posts: 16
Location: Berlin
Hi there,
if you need a quick solution, edit the MigraDoc.Rendering.FontHandler Class:
Code:
      private static Dictionary<string, XFont> _FontCache = new Dictionary<string, XFont>();

      /// <summary>
      /// Converts an DOM Font to an XFont.
      /// </summary>
      /// <param name="font"></param>
      /// <returns></returns>
      internal static XFont FontToXFont(Font font, bool unicode) {
         string key = font.Name + "#" + font.Size + "#" + GetXStyle(font);

         if (_FontCache.ContainsKey(key)) {
            XFont cachedFont = _FontCache[key];
            return cachedFont;
         }

         XPdfFontOptions options = null;
         if (unicode) {
            options = new XPdfFontOptions(false, true);
         }

         XFontStyle style = GetXStyle(font);
         XFont xFont = new XFont(font.Name, font.Size, style, options);
         _FontCache.Add(key, xFont);
         return xFont;
      }


Regards,
André


Top
 Profile  
Reply with quote  
 Post subject: On table creation
PostPosted: Mon Aug 20, 2007 7:46 am 
Offline

Joined: Thu Aug 16, 2007 7:10 am
Posts: 1
Mr. André (aknuth) can u mention what change needs to be done to make the table rendering faster in PDF sharp?

I had changed the code accordingly as u had mentioned but still the performance is extremely slow.

It takes around 2 min to create table with 6 col in 3 pages. Unless the performance is improved , I will not be able to use it.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Aug 20, 2007 6:48 pm 
Offline

Joined: Fri Mar 23, 2007 11:37 pm
Posts: 16
Location: Berlin
the improvement i suggested speeds up the font allocation, I dunno any in depth details of the rendering process, so reasons for further slow rendering are beyond my knowledge, sorry.

regards,
andré


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 16, 2007 12:14 pm 
Offline

Joined: Tue Oct 16, 2007 12:00 pm
Posts: 1
Sry, but this problem has nothing to do with fonts, etc.

Its more difficult. The MicraDoc Lite engine uses reflection to access any property of the internal DOM by MetaData and Attributes.

We used JetBrains .NetTrace to analyse the bottlenecks. It clearly shows, that for a table with about 1000 rows and 3 columns more than 12-14 million reflection operations (for only two properties!!) will be evaluated.
Named the generic get/set operators "setValue" and "getValue" of nullable types. (btw: which are not implemented as "nullable types". They really implemented an custom attribute system to mimic this feature :shock: )
And that is the real problem.

The MicraDocLite engine does even not use any kind of caching to improve the performance for reflection operations.

For this, a quick solution can not be found. The only way would be to implement a kind of caching or generally avoid the usage of reflection here.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 23, 2007 3:19 pm 
Offline

Joined: Tue Oct 23, 2007 2:07 pm
Posts: 3
Hello,

There's definitely serious performance problem with rendering large tables. And Roland is right - the main bottleneck is overuse of reflection. For example, the most common operations is to get an index of a column (or a row) looks like:
Code:
        if (IsNull("Index"))
        {
          Columns clms = this.Parent as Columns;
          SetValue("Index", clms.IndexOf(this));
        }
        return index;
It took nearly half an hour on my workstation to render a table with just about 360 rows :shock:
When I changed type of "index" field from NBool to bool? and replaced your code with:
Code:
       if (index == null)
       {
           Columns clms = (Columns)this.Parent;
           index = clms.IndexOf(this);
       }
       return index;
Now it works like 10 times faster! And takes about 3-4 minutes to render the same table which is still too bad.

I can imagine that you wanted to make your engine more flexible with these field but why reflection, why not dictionary, for example?

Also I wonder why do you use "home made" INullable interface instead of nullable types?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 23, 2007 3:43 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
AnKor wrote:
Also I wonder why do you use "home made" INullable interface instead of nullable types?

Thanks to you and Roland for pointing out the bottlenecks.

PDFsharp was written with and for .NET 1.1.
Nullable Types were introduced with .NET 2.0 - along with many other useful generic types.

PDFsharp no longer supports .NET 1.1 and we have begun to use some of the new generic types in PDFsharp.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 23, 2007 3:54 pm 
Offline

Joined: Tue Oct 23, 2007 2:07 pm
Posts: 3
Unfortunately this will be lots of work to change NSomething to nullable types.

Anyway, your library looks very good and I think I'll manage to make its performance suitable for my project! Thanks! :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Oct 24, 2007 1:01 pm 
Offline

Joined: Fri Mar 23, 2007 11:37 pm
Posts: 16
Location: Berlin
Hi AnKor,
could you please let others participate in the performance enhancements? That would be very helpful even it is - and hopefully is - only a short term solution.
Regards,
André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Oct 24, 2007 7:47 pm 
Offline
empira Employee
User avatar

Joined: Thu Oct 12, 2006 10:07 pm
Posts: 49
Location: Cologne, Germany
Hello AnKor,

it is very interesting that MigraDoc becomes 10 times faster with your optimization.
Quote:
but why reflection, why not dictionary

An earlier implementation of MigraDoc was based on our internal framework which uses reflection combined with a smart caching algorithm. Before we made MigraDoc Open Source, we decided to rewrite the framework code we need in MigraDoc. Because of limited resources the implementation of the object model is just semantically correct, but far beyond from optimal.

Is it possible that you send me your modified version of MigraDoc? I would like to make some tests. If everything works fine, we will refactor the object model and release it as soon as possible.

If you like just send the code to Stefan.Lange@pdfsharp.com.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Nov 12, 2007 2:19 pm 
Offline

Joined: Tue Oct 23, 2007 2:07 pm
Posts: 3
I'm back :)

Stefan,
I've sent you an email with my changes.

aknuth,
Perhaps, you're right and I should publish my modifications, but they're very incomplete and I think I better let authors to review them first.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Nov 12, 2007 4:20 pm 
Offline

Joined: Fri Mar 23, 2007 11:37 pm
Posts: 16
Location: Berlin
excellent, as long as the community gets its feedback.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 20, 2007 6:11 pm 
Offline

Joined: Tue Nov 20, 2007 6:05 pm
Posts: 1
Hi AnKor,

I would be glad to see your modifications for this table rendering performance issue. PdfSharp is really a nice lib, but this slow rendering is really problematic in production.

Could you please send me your source code at : sbaviere [at] premiumconsulting [dot] fr ?

Thanks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 17, 2007 8:33 pm 
Offline

Joined: Fri Mar 23, 2007 11:37 pm
Posts: 16
Location: Berlin
Has there been any progress yet?

Regards,
André


Top
 Profile  
Reply with quote  
 Post subject: Progress ?
PostPosted: Wed Feb 06, 2008 9:03 am 
Offline

Joined: Wed Feb 06, 2008 8:32 am
Posts: 1
We are about to choose a pdtWriter for an upcoming project, and I've been evaluating PDFsharp (with MigraDoc) and the performance with tables is really a big issue. Our report will be hundreds of pages and just testing a table spanning 10 pages took about 7s to generate (on our Intel Core 2 QUAD).

As I understand this has been an issue for years?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 13, 2008 1:19 pm 
Offline

Joined: Mon Oct 13, 2008 1:18 pm
Posts: 1
Any news on performance? this is also killing me!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Oct 15, 2008 10:50 am 
Offline

Joined: Tue Oct 14, 2008 7:53 pm
Posts: 4
Jonesy wrote:
Any news on performance? this is also killing me!

+1

TIA


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 24, 2011 11:24 am 
Offline

Joined: Thu Mar 24, 2011 11:19 am
Posts: 2
Are there any news for this Toppic??

i still have problems in some cases with RenderDocument.
Code:
            myMigraDocument.UseCmykColor = True
            myMigraDocument.Info.Title = myValueFromForm_docName
            myMigraDocument.Info.Author = System.Environment.UserName

            myMigraDocument.Info.Comment = myArchivHandler.getValueFromForm_Comment

            Const unicode As Boolean = False
            Const embedding As PdfFontEmbedding = PdfFontEmbedding.Always

            ' Create a renderer for the MigraDoc document.
            Dim pdfRenderer As PdfDocumentRenderer = New PdfDocumentRenderer(unicode, embedding)

            ' Associate the MigraDoc document with a renderer
            pdfRenderer.Document = myMigraDocument

            ' Layout and render document to PDF
            pdfRenderer.RenderDocument()

            ' Save the document
            pdfRenderer.PdfDocument.Save(pFileName)



Or did someone see any problem in the Code?

Thx
magges


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 162 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group