Skip to content

perf: reuse the last scaled render for cropped get_image calls - #405

Closed
ExtReMLapin wants to merge 2 commits into
docling-project:mainfrom
ExtReMLapin:perf/cache-scaled-render
Closed

ExtReMLapin wants to merge 2 commits into
docling-project:mainfrom
ExtReMLapin:perf/cache-scaled-render

Conversation

@ExtReMLapin

Copy link
Copy Markdown
Contributor

PageParseResult.get_image(scale=..., cropbox=...) renders the whole page and then crops. Docling's OCR stage asks for one crop per OCR region, all at the same scale (3.0), so a page with N regions is rendered N times.

Keep the last non-default-scale render next to _default_image, which is already cached the same way.

On a 5-page PDF where layout sends 11 regions to OCR (11 renders at 3x, 5 needed), docling conversion goes 2.77 s → 2.38 s (median of 5, A100). Output unchanged; docling's tests/test_backend_docling_parse.py and the RapidOCR e2e OCR test pass.

Diagnosis, commit message, PR text and PR creation done with help from Claude.

Signed-off-by: ExtReMLapin <3909752+ExtReMLapin@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @ExtReMLapin, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@PeterStaar-IBM
PeterStaar-IBM self-requested a review October 12, 2026 13:53
Caching every non-default-scale render keeps one full page image per
live page. Docling asks for full-page images at images_scale in
preprocessing and at scale 2 for tables, and caches those itself in
Page._image_cache, so the parser cache only duplicated them. On a
40-page scanned document with images_scale=2 that added about 330 MiB
at peak.

Keep the render only when the request has a cropbox, which is the OCR
case this cache is for. A full-page request still reuses a cached
render at the same scale.

Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
@cau-git

cau-git commented Oct 28, 2026

Copy link
Copy Markdown
Member

@ExtReMLapin Thanks for this improvement. I made a small change such that this only fires for crop-requests.

@cau-git

cau-git commented Oct 28, 2026

Copy link
Copy Markdown
Member

@ExtReMLapin your work is now included in #429 with your original commits. I am therefore closing this PR. Thanks!

@cau-git cau-git closed this Oct 28, 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.

2 participants