Skip to content

Conversation

@leonardopbatista
Copy link
Contributor

Each drawing operation previously created and committed a new shape, causing significant performance overhead. This update introduces a shared shape instance reused across operations and committed once in finalize().

This change was inspired by a suggestion from the PyMuPDF maintainer in pymupdf/PyMuPDF#3800. Performance improvements can exceed 100x in documents with many entities.

Each drawing operation previously created and committed a new shape, causing significant performance overhead. This update introduces a shared shape instance reused across operations and committed once in finalize().

This change was inspired by a suggestion from the PyMuPDF maintainer in pymupdf/PyMuPDF#3800. Performance improvements can exceed 100x in documents with many entities.
mozman added a commit that referenced this pull request May 3, 2025
@mozman mozman merged commit 9bbe444 into mozman:master May 3, 2025
10 of 11 checks passed
@mozman
Copy link
Owner

mozman commented May 3, 2025

Thank you!

The file size of PDFs appears to have increased, but that is a small price to pay for the enormous performance gain.

@mozman
Copy link
Owner

mozman commented May 3, 2025

I was wrong, the size of the new PDFs is also smaller! In average: 38x faster and 2.5x smaller!

image

@leonardopbatista leonardopbatista deleted the pymupdfoptimization branch May 3, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants