Skip to content

perf: let callers pass pre-rendered PDF pages so hi_res renders each page once - #524

Open
CyMule wants to merge 2 commits into
mainfrom
perf/pdf-render-once
Open

CyMule wants to merge 2 commits into
mainfrom
perf/pdf-render-once

Conversation

@CyMule

@CyMule CyMule commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What

DocumentLayout.from_file and process_file_with_model accept image_paths: page images the caller already rendered from the PDF. When given, the PDF is not rendered again, and each page keeps its path, so later page operations (such as annotate) read the caller's image instead of re-rendering.

Nothing changes for callers that don't pass it. Pages rendered internally still keep no path, since their temporary directory is deleted on return.

Why

A hi_res request renders every page of the PDF several times: once here for layout inference, then again in unstructured for OCR and once more per extracted image type. Each render is the same work (same dpi, same pages), so the only way to stop paying for it twice is to let the caller hand the pages in.

before: inference render → OCR render → image-extraction render → table-extraction render   (4 × pages)
after:  one render, shared by all four                                                       (1 × pages)

Release

Listed under 1.6.18, which is on main and not yet released. The paired unstructured PR (Unstructured-IO/unstructured#4530) can pin it after 1.6.18 is published.

Validation

  • New tests: image_paths skips the render and is kept on each page; process_file_with_model forwards it; internally rendered pages keep no path. The path test fails without the change.
  • Unit suite: 429 passed. Ruff clean.
  • End-to-end measurements (up to 24% faster when extracting images/tables) are in the paired unstructured PR.

@CyMule

CyMule commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@CyMule I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Shadow auto-approve: would not auto-approve. This PR does not meet the repository auto-approval settings.

Re-trigger cubic

@CyMule
CyMule marked this pull request as ready for review November 10, 2026 16:53
@CyMule
CyMule force-pushed the perf/pdf-render-once branch from fce0680 to d58479f Compare November 10, 2026 16:53

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 3 files (changes from recent commits).

Shadow auto-approve: would not auto-approve. This PR does not meet the repository auto-approval settings.

View guided diff | Re-trigger cubic

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