pyfpdf icon indicating copy to clipboard operation
pyfpdf copied to clipboard

performance improvements

Open marcelotduarte opened this issue 9 years ago • 6 comments

With this speedup, when you have various pages with png images, the improvements is significant. As a example, I used an old dual core machine, with 104 png images (16MB per image), to generate a pdf, 1 image per page. The time consuming before was 1 minute and 28 seconds. After this patch, the time is 6 seconds!!! Yes, 6 seconds, 14,7x faster!

marcelotduarte avatar Feb 16 '16 07:02 marcelotduarte

The general idea sounds good to me. Writing into BytesIO or similar should be well optimized, and concatenating strings in Python performs badly in this sort of scenario.

vadmium avatar Feb 16 '16 10:02 vadmium

@reingart: This patch is good to be merged?

marcelotduarte avatar Aug 02 '16 17:08 marcelotduarte

Thank you for this performance work. Swapping in this version reduced the build time for a 112MB, 228 page PDF containing over 4500 images from 40 minutes to 30 seconds - an awesome improvement.

aussig avatar Jan 10 '19 08:01 aussig

This offers a huge performance benefit, any chance this will get merged?

alallier avatar Mar 28 '21 04:03 alallier

@alallier you may want to check out #171 and also check out this link to see that the fpdf2 fork uses a bytearray instead of a string (and is otherwise maintained):

https://github.com/PyFPDF/fpdf2/blob/master/fpdf/fpdf.py#L178

alexp1917 avatar Mar 28 '21 18:03 alexp1917

Thanks for the link. I noticed shortly after that this project was abandoned which is unfortunate

alallier avatar Mar 30 '21 15:03 alallier