-
Notifications
You must be signed in to change notification settings - Fork 254
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
FPDFRecorder frequent usage makes document generation slow #1092
Comments
Hi @dmail00
Yes indeed, there is even a unit test for that: https://github.com/py-pdf/fpdf2/blob/2.7.7/test/test_recorder.py#L30
Great if you found some solution that fits your needs 🙂 I think it'd be great to improve It is not immediately clear to me what is your use case there: could you provide some minimal script that reproduces the performance issue you mentioned, please? This would help us to understand through which methods calls the Also, if you already found a solution for your problem, what is your intent in opening this issue? |
If performances are better, I think that instead of calling |
This works really well, thanks and is just as fast as what I was doing. I did change it to return the height
It would have to be a contrived example, as what is currently written is pulled in from an external source and contains personal information.
It was solely to make you aware of the problem and provide a potential solution. |
I opened PR #1127 to improve this |
It is not immediately apparent to me why the rewind on FPDFRecorder copies the singleton FPDF state, was it imagined that this would be rewound multiple times?
From looking at the commit history of this file, it was introduced around version 2.3; the initial commit [1] does not contain this deepcopy yet strangely the next commit to this file is modifying an already present deepcopy [2].
The reason for asking this, is that I am generating 30 or so documents at a time with a similar format, each with five heading and this is slow, it is copying the singleton state twice for each header which seems like madness. The speed can be drastically improved by removing the second deepcopy or at least using a boolean flag to copy or not; however it can be even better using some logic that at least fits my needs. This is:
start_section
** if this new y would exceed the page break trigger create a page
** render the marked sequence
* margins includes any possible heading borders.
** Anything less than four lines, to me at least, does not make sense in putting a header on this page
[1] ea834ec
[2] 9fb2c3b
The text was updated successfully, but these errors were encountered: