Skip to content

LDEV-6446 Reduce heap when thumbnailing PDFs with large page images - #63

Open
shane-tw wants to merge 1 commit into
lucee:masterfrom
shane-tw:thumbnail-large-pdf-memory
Open

LDEV-6446 Reduce heap when thumbnailing PDFs with large page images#63
shane-tw wants to merge 1 commit into
lucee:masterfrom
shane-tw:thumbnail-large-pdf-memory

Conversation

@shane-tw

@shane-tw shane-tw commented Jul 21, 2026

Copy link
Copy Markdown

Jira: https://luceeserver.atlassian.net/browse/LDEV-6446

Problem

cfpdf action="thumbnail" renders the source page at full resolution before scaling it down to the thumbnail size. When the first page holds a high-resolution image, the full raster is decoded into heap first, so a single thumbnail request can use hundreds of MB and OOM the rendering process — even though the output is only ~140px.

Change

In PDFUtil.thumbnail(...):

  • pdfRender.setSubsamplingAllowed(true) so PDFBox decodes the page near thumbnail resolution instead of decoding the full-size image and then downscaling.
  • Load the document in a try-with-resources so it is always closed (it previously wasn't).

Measured effect

Rendering a 140px thumbnail of a page whose first page is a 6000×6000 image, under -Xmx512m, using the same PDFBox 3.0.7 this extension depends on:

peak heap over baseline output time
before +423.6 MB valid 148×210 JPEG 2765 ms
after +19.8 MB valid 148×210 JPEG 1447 ms

~21× less heap, faster, identical thumbnail. A large file with a light first page was unaffected either way (+3.0 vs +3.2 MB), as expected — the cost scales with page-1 content, not file size.

Thumbnails decoded the source page at full resolution before
downscaling, so a first page holding a high-resolution image could use
hundreds of MB of heap and OOM the rendering pod. Enable PDFRenderer
subsampling so the page is decoded near thumbnail resolution, and close
the document afterwards.
@shane-tw
shane-tw force-pushed the thumbnail-large-pdf-memory branch from 8308841 to 1736cab Compare July 21, 2026 12:31
@shane-tw shane-tw changed the title Reduce heap when thumbnailing PDFs with large page images LDEV-6446 Reduce heap when thumbnailing PDFs with large page images Jul 21, 2026
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.

1 participant