Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF make takes 50seconds to print document with one image and 75 tables #798

Closed
Dannybrown2710 opened this issue Dec 27, 2016 · 33 comments
Closed

Comments

@Dannybrown2710
Copy link

Hi @bpampuch I am facing issue in generating document through PDFmake. I tried switching to new version i.e 0.1.22 but still its way slow. Can I get any resolution or answer to this issue?
Thanks in advance

@liborm85
Copy link
Collaborator

Version 0.1.22 includes fix for performance from issue #280. I do not know how large is your document. Partially should reduce time to generate document from previous version pdfmake. It is possible that your document contains a performance problem about which we know nothing yet.

@Dannybrown2710
Copy link
Author

Hi @liborm85 , my document size is around 75-100 pages one containing image and rest containing tables. I tried to use the new version 0.1.22 but it was slower than the 0.1.20. I tried to use this in 0.1.20
function flow(stream) {
var state = stream._readableState;
debug('flow', state.flowing);
if (state.flowing) {
do {
var chunk = stream.read(Number.MAX_SAFE_INTEGER); // add this here in stream.read(xxx);
} while (null !== chunk && state.flowing);
}
}
yet it takes around one minute to generate. In word document generation, it takes just 3-5seconds.
I am really in need of some help/
Kindly help me out in some or the other way.

@Dannybrown2710
Copy link
Author

My document containes dynamically generated tables from json.
So around 75 - 80 tables are generated dynamically from a function and then these are printed in the document.

@Dannybrown2710
Copy link
Author

There was one thing that I noticed was if the document was 40pages, it was printing in 3seconds, but as soon as it became 44pages, it took 23seconds. Is there any method that is having restriction or something?
40 pages means one image and around 10 tables.

@Dannybrown2710
Copy link
Author

@jthoenes Any help or input that you could share??
I have seen this , for 40pages or some amount of pages, this works fine, as soon as one page increases, the performance degrades immediately by large fraction of seconds.
Any guidance/help/assistance will be highly appreciated sir...

@liborm85
Copy link
Collaborator

Pdfmake 0.1.22+ use the newer lodash 4.17.2 and not only that (see 91be970). Maybe it has some influence on it.

@Dannybrown2710
Copy link
Author

Ok sir, but what is the actual relation of number of pages? how can increase in one page degrade the performance?

@liborm85
Copy link
Collaborator

I do not know. Maybe someone else comes up with an idea to solve this problem.

@Bazze
Copy link

Bazze commented Dec 29, 2016

What browser are you having these issues in? If you're using IE11 you will have to make sure to polyfill the Number.MAX_SAFE_INTEGER constant.

@Dannybrown2710
Copy link
Author

@liborm85 Thanks alot for your valuable time
@Bazze Hi , IE11 is slow to download, is there any piece of code or reference that you could share? thanks in advance.

@Bazze
Copy link

Bazze commented Dec 29, 2016

@Dannybrown2710 Have you tried your code in another browser? Is it equally slow in e.g. Chrome? If not, it's probably the missing constant in IE11 as I mentioned. Try polyfilling it yourself or use a service like polyfill.io to do it.

@liborm85
Copy link
Collaborator

Released version does not use a constant Number.MAX_SAFE_INTEGER, but equivalent number 9007199254740991 for compatibility with IE.

(webpack replacer:

return 'stream.read(9007199254740991)';
)

@Bazze
Copy link

Bazze commented Dec 29, 2016

Aha! Then I'm clueless.

@Dannybrown2710
Copy link
Author

I tried to use 0.1.22 , but it is for no reason slower . As @liborm85 stated , it might be because of loadash. Previous version with 9007199254740991 works well in Chrome but not in IE 11. @Bazze Can you share the tweaked js which you used for printing pdf faster in your application?

@Bazze
Copy link

Bazze commented Dec 30, 2016

@Dannybrown2710 I haven't really done any other changes that should affect performance, but I'm using the code found here: https://github.com/Bazze/pdfmake/tree/feature/wide-tables-without-filesaver-2093de79

On that branch I've implemented a feature which splits tables that becomes wider than the page width plus that I've removed the bundled FileSaver since I include it separately on a global scope.

@Dannybrown2710
Copy link
Author

@Bazze I have tried your file , its amazing. I just have a small doubt, is it possible to fit one table in one page without getting it cropped? Auto-sizing , or something?

@Bazze
Copy link

Bazze commented Jan 3, 2017

I'm not sure if I understand you @Dannybrown2710 but if you set your column widths to * (auto column size) pdfmake will make best effort to fit the table on the page. However, if it doesn't manage to keep the table width within the page boundaries my changes will kick in and split the table.

We're kind of getting off topic in this issue, are you still having the performance issues?

@Dannybrown2710
Copy link
Author

@Bazze the height is what I am talking about.
for performance bit I have tried using the number itself 9007199254740991, but it seems not to work,for chrome the performance is good, and I am sticking to version 0.1.20 not 0.1.22.
IE still takes alot of time or breaks in between stating long script is not responding.

@Bazze
Copy link

Bazze commented Jan 4, 2017

@Dannybrown2710 Alright, I'm not sure about the height since that haven't been an issue for my use case. Maybe the dontBreakRows or keepWithHeaderRows settings could help you?

Regarding the performance issues you probably need to get some profiling done in IE to narrow down where the issue resides.

@tsiegleauq
Copy link
Contributor

tsiegleauq commented Jan 25, 2017

We also face some performance issues for out HTML to PDF parser. The HTML to Json document which works for PDFmake works in less than seconds, but the actual PDF generation consumes quite some time. On a beefy machine, creating 20 Pages takes on average 10 seconds in latest chrome and PdfMake 1.24

firefox usually needs 21 seconds for the same document.
(time grows perfectly linear according to the number of pages, we use text only)
Anything known?
pdfmake.1.2.4-performance.pdf

I gonna paste our JSON string we use for testing somewhere.
https://paste.kde.org/pmkpttzig

there is also the whole Roboto-font in Base64 included.

@liborm85
Copy link
Collaborator

liborm85 commented Jan 29, 2017

I used definition from previous post and I did some performance tests. I tried different versions of pdfkit.

pdfmake version Chrome Firefox Edge IE11
master (using pdfkit 0.8.0) 13 s 32 s 130 s ca. 200 s
master (build with pdfkit 0.7.1) 3 - 4 s 4 s 11 s 14 s
0.1.20 + speed hack #280 (comment) (using pdfkit 0.7.1) 3 - 4 s 6 s 19 s 13 s

According to this table must have a performance problem especially with pdfkit.

@liborm85
Copy link
Collaborator

I added tests for Edge and IE to the table.

@liborm85
Copy link
Collaborator

liborm85 commented Feb 1, 2017

I'm created issue in pdfkit - foliojs/pdfkit#615

@devongovett
Copy link
Contributor

Merged a performance optimization for kerning in fontkit. foliojs/fontkit#70 Please re-install and try again.

@liborm85
Copy link
Collaborator

New tests:

pdfmake version Chrome Firefox Edge IE11
(NEW) pdfmake master with pdfkit 0.8.0 and fontkit 1.5.4 12 s 18 s 80 s 96 s
pdfmake master with pdfkit 0.8.0 and old fontkit 1.5.2 13 s 32 s 130 s ca. 200 s
pdfmake master with pdfkit 0.7.1 3 - 4 s 4 s 11 s 14 s

Test scripts:
performance-test.zip

@devongovett Generate PDF file is faster, but still slow compared to pdfkit version 0.7.1. Another idea for fix?

@awoywood
Copy link

Hi @liborm85 what are the main differences between version 0.8.0 and 0.7.1 ?

I'm thinking about going back ... I'll use the library included in the zip you just posted.

@liborm85
Copy link
Collaborator

Hi @awoywood
There are release notes for version 0.8.0: https://github.com/devongovett/pdfkit/releases/tag/v0.8.0
Version 0.8.0 adds many new things, and primarily adds support for other font formats.

Library in zip with pdfkit 0.7.1 to generate basic texts works, but fails many tests. It is not intended for everyday use. I hope that @devongovett will solve the performance problem.

@liborm85
Copy link
Collaborator

liborm85 commented Mar 25, 2017

Released new version (0.1.27) with fontkit 1.5.4 which contanins this partly performance fix.

@devongovett
Copy link
Contributor

Just implemented a cache around fontkit in PDFKit: foliojs/pdfkit@6e9e58f. This should improve performance significantly. It is released in PDFKit v0.8.2.

In order to increase cache efficiency, it splits up text by words and makes a separate fontkit call for each one, then caches the results. Please let me know if you see any bugs because of that. Particularly, any fonts with GSUB or GPOS adjustments around space characters won't be triggered anymore, though this should be rare.

@liborm85
Copy link
Collaborator

New tests:

pdfmake version Chrome Firefox Edge IE11
(NEW) pdfmake master with pdfkit 0.8.2 4 - 5 s 6 s 16 s 19 s
pdfmake master with pdfkit 0.8.0 and fontkit 1.5.4 12 s 18 s 80 s 96 s
pdfmake master with pdfkit 0.8.0 and old fontkit 1.5.2 13 s 32 s 130 s ca. 200 s
pdfmake master with pdfkit 0.7.1 3 - 4 s 4 s 11 s 14 s

Test scripts:
performance-test.zip

@devongovett Great work. Thanks.

@liborm85
Copy link
Collaborator

New version pdfmake 0.1.29 with new pdfkit released.

@liborm85
Copy link
Collaborator

liborm85 commented Jun 2, 2017

Performance problem solved.

@liborm85 liborm85 closed this as completed Jun 2, 2017
@jaysonduenas
Copy link

Thanks all for the fix! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants