Skip to content

Optimize Jasper exporter memory usage and reduce PDF size#3624

Merged
sebr72 merged 2 commits intomapfish:masterfrom
sogelink:f/optimizeJasper
Jun 2, 2025
Merged

Optimize Jasper exporter memory usage and reduce PDF size#3624
sebr72 merged 2 commits intomapfish:masterfrom
sogelink:f/optimizeJasper

Conversation

@arnaudboudier-sogelink
Copy link
Copy Markdown
Contributor

@arnaudboudier-sogelink arnaudboudier-sogelink commented May 13, 2025

We use a WeakHashMap in JRPdfExporter as an image cache to allow it to be automatically cleared when memory becomes low, while preserving the functionality (which helps produce a smaller PDF).
Test added : JRPdfExporterWeakHashMapTest explains that:
JRDExporter uses loadedImagesMap to save reference of a image that will be put into the pdf. So when the pdf is exported, references are used inside the pdf to point to the same image and prevent to duplicate the image into the pdf.

@sbrunner sbrunner added the bug Something isn't working label May 14, 2025
Copy link
Copy Markdown
Contributor

@sebr72 sebr72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Thanks lot.

@sebr72
Copy link
Copy Markdown
Contributor

sebr72 commented May 15, 2025

@sbrunner Could you please confirm this strategy for clearing cache is not conflicting with other parts of MFP, in case I forgot something.

@sbrunner
Copy link
Copy Markdown
Member

@sebr72 difficult to be certain, for me, we should go ahead with that :-)

@arnaudboudier-sogelink
Copy link
Copy Markdown
Contributor Author

I have coded your suggestion and added a test, not sure if its the most relevant. It seems ok but i'm not an expert. This MR in my opinion is a small optimization but can be usefull.

@sbrunner sbrunner changed the title Optimize jasper exporter memory usage Optimize Jasper exporter memory usage May 16, 2025
@sebr72
Copy link
Copy Markdown
Contributor

sebr72 commented May 27, 2025

@arnaudboudier-sogelink What do you mean by MR in this sentence:
"This MR in my opinion is a small optimization but can be usefull." ?

Copy link
Copy Markdown
Contributor

@sebr72 sebr72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Thanks.
I noticed you used MR Corrections as a commit comment, which hides the value of the content of your commit. Could you please amend it to something more specific (e.g add test to demonstrate pdf memory size impact) ?

@arnaudboudier-sogelink
Copy link
Copy Markdown
Contributor Author

@sebr72 I have change the text commit

@sebr72 sebr72 self-requested a review June 2, 2025 09:04
Copy link
Copy Markdown
Contributor

@sebr72 sebr72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@sebr72 sebr72 merged commit 77cdce8 into mapfish:master Jun 2, 2025
6 checks passed
@arnaudboudier-sogelink arnaudboudier-sogelink deleted the f/optimizeJasper branch June 3, 2025 07:17
@geo-ghci-int geo-ghci-int bot added this to the 3.32.0 milestone Jun 3, 2025
@sbrunner sbrunner added enhancement New feature and removed bug Something isn't working labels Jun 3, 2025
@sebr72 sebr72 changed the title Optimize Jasper exporter memory usage Optimize Jasper exporter memory usage and reduce PDF size Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants