Skip to content

perf(pdf): skip the per-character word walk for text boxes with no overlapping link - #4680

Open
KRRT7 wants to merge 1 commit into
Unstructured-IO:mainfrom
KRRT7:perf/skip-word-walk-without-annotations
Open

KRRT7 wants to merge 1 commit into
Unstructured-IO:mainfrom
KRRT7:perf/skip-word-walk-without-annotations

Conversation

@KRRT7

@KRRT7 KRRT7 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a page has any link annotations, process_page_layout_from_pdfminer() and _pdfminer_page_elements() called get_words_from_obj() for every LTTextBox on the page, then used its result only for the annotations that overlap that box. get_words_from_obj() walks every character of the box. It now runs only when check_annotations_within_element() returned at least one annotation. get_words_from_obj() has no side effects, so output is unchanged.

Performance

Walltime, pytest-codspeed run locally (Apple Silicon), process_page_layout_from_pdfminer over all 16 pages of example-docs/pdf/layout-parser-paper.pdf (109 link annotations), repeated runs:

before after
all pages ~11.0 ms ~6.1 ms

cProfile had get_words_from_obj at ~41% of this function before the change.

Validation

  • test_unstructured/partition/pdf_image/test_pdfminer_processing.py, test_pdf.py and test_merge_elements.py pass.

View guided diff

This branch has not been deployed

No deployments
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