Skip to content

feat(pdf): adopt performance-oriented core-pdfminer.six fork - #4411

Open
KRRT7 wants to merge 4 commits into
Unstructured-IO:mainfrom
KRRT7:core-pdfminer-six-migration
Open

feat(pdf): adopt performance-oriented core-pdfminer.six fork#4411
KRRT7 wants to merge 4 commits into
Unstructured-IO:mainfrom
KRRT7:core-pdfminer-six-migration

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

This migrates Unstructured’s PDF extraction path to core-pdfminer.six, a performance-oriented fork of pdfminer.six.

core-pdfminer.six preserves the parsing and extraction semantics of upstream pdfminer.six under the core_pdfminer_six namespace. It passes the same upstream test cases, with only the import namespace adjusted.

This PR:

  • Adds core-pdfminer-six as a dependency.
  • Migrates Unstructured’s PDF imports to core_pdfminer_six.
  • Updates dependency checks, runtime patch targets, tests, and logging configuration.
  • Removes the legacy PSBaseParser monkey patch because the corresponding fixes are already included in the fork.
  • Leaves the existing pdfminer.six image-extra dependency unchanged for now.

Performance

Benchmarks against the upstream baseline across Python 3.10, 3.11, and 3.12 showed:

  • 1.23× overall geometric-mean speedup
  • 1.37× speedup on representative workloads
  • 1.51× faster converters
  • 1.42× faster parsing
  • 1.31× faster layout processing
  • Approximately 12–14% lower peak memory usage
  • Improved scalability for deep cross-reference chains that exceed upstream recursion limits

Compatibility

The fork maintains upstream parsing and extraction behavior. The package namespace is intentionally distinct, allowing core-pdfminer.six and pdfminer.six to coexist in the same environment.

Testing

  • The complete upstream pdfminer.six test suite passes against the fork.
  • Ruff checks passed.
  • 177 focused Unstructured PDF integration tests passed.

Review in cubic

@socket-security

socket-security Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedpypi/​core-pdfminer-six@​0.0.098100100100100

View full report

@KRRT7

KRRT7 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

core-pdfminer.six retains the original project’s license, and I have no intention of changing it. I also plan to actively maintain the fork and continue improving its performance.

@KRRT7
KRRT7 marked this pull request as ready for review July 17, 2026 22:16
@KRRT7

KRRT7 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@badGarnet @cragwolfe for your review.

@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 2 files (changes from recent commits).

Shadow auto-approve: would auto-approve. Migrates to a performance-oriented fork of pdfminer.six while preserving semantics, removing a now-included monkey-patch. The change is bounded and clearly beneficial with no new exposure or tradeoffs.

Re-trigger cubic

@KRRT7

KRRT7 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Unstructured performance comparison

I benchmarked upstream main (d309caf8) against this branch (d10999b2) using Unstructured’s quick_partition_bench.py harness on Python 3.12.13.

PDF main PR branch Speedup Elements
a1977-backus-p21.pdf 59.73 ms 40.02 ms 1.49× 41
copy-protected.pdf 56.73 ms 45.38 ms 1.25× 32
reliance.pdf 149.05 ms 120.94 ms 1.23× 75
pdf-with-ocr-text.pdf 17.61 ms 10.51 ms 1.68× 20
Aggregate 70.78 ms 54.21 ms 1.31×

This is a 23.4% reduction in warm partition latency. Element counts matched exactly for every document.

Methodology:

  • 30 measured warm runs per PDF after 3 warmups
  • 120 samples per revision
  • Same virtual environment and locked dependencies
  • strategy="fast"

Cold process performance was effectively unchanged (7.027 seconds on main versus 7.013 seconds on this branch) because Unstructured process startup dominates that measurement.

The broader CI partition benchmark also passes.

@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

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

Re-trigger cubic

Comment thread pyproject.toml Outdated

@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 2 files (changes from recent commits).

Shadow auto-approve: would auto-approve. Bounded, mechanical migration to a compatible performance-oriented fork, preserving all semantics; only import paths and a now-included monkey-patch removal change.

Re-trigger cubic

@KRRT7

KRRT7 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@agarctfi

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