Skip to content

Lazy Import of heavy weight modules - #5205

Merged
JorjMcKie merged 1 commit into
mainfrom
lazy-layout1
Oct 23, 2026
Merged

JorjMcKie merged 1 commit into
mainfrom
lazy-layout1

Conversation

@JorjMcKie

Copy link
Copy Markdown
Collaborator

Version 2.0 of PyMuPDF unconditionally also imports pymupdf-layout and pymupdf4llm. This increases the duration of the import statement by almost an order of magnitude. Applications not using 4LLM or Layout perceive this as intolerable especially when also spawning subprocesses.

This fix postpones the imports of pymupdf4llm and layout until they are used for the first time.

For this fix to work, the same-named branch of pymupdf4llm must also be available.

Version 2.0 of PyMuPDF unconditionally also imports pymupdf-layout and pymupdf4llm. This increases the duration of the import statement by almost an order of magnitude.
Applications not using 4LLM or Layout perceive this as intolerable especially when also spawning subprocesses.

This fix postpones the imports of pymupdf4llm and layout until they are used for the first time.

For this fix to work, the same-named branch of pymupdf4llm must also be available.
@JorjMcKie
JorjMcKie merged commit 1d34e04 into main Oct 23, 2026
3 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 23, 2026
@JorjMcKie
JorjMcKie deleted the lazy-layout1 branch October 26, 2026 12:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants