Skip to content

Postpone heavy imports until actually needed - #5203

Closed
JorjMcKie wants to merge 1 commit into
mainfrom
lazy-layout
Closed

JorjMcKie wants to merge 1 commit into
mainfrom
lazy-layout

Conversation

@JorjMcKie

Copy link
Copy Markdown
Collaborator

With version 2.0 we import layout and pymupdf4llm unconditionally together with pymupdf itself. This causes importing the full stack of many dozens of heavy weight modules and increases the duration of import pymupdf by almost an order of magnitude. For apps not intending to use layout or pymupdf4llm at all, this means an inacceptable burden. This fix postpones the import of the modules until their first use.

With version 2.0 we imported `layout` and `pymupdf4llm` unconditionally together with pymupdf itself.
This caused importing the full stack of many dozens of heavy weight modules and increased the duration of `import pymupdf` by almost an order of magnitude.
For apps not intending to use layout or pymupdf4llm at all, this is an inacceptable burden.
This fix postpones the import of the modules until their first use.
@JorjMcKie

Copy link
Copy Markdown
Collaborator Author

Note that this fix is complete only with the fix in the same-named branch of pymupdf4llm.

@JorjMcKie JorjMcKie closed this Oct 24, 2026
@JorjMcKie
JorjMcKie deleted the lazy-layout branch October 24, 2026 09:43
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 24, 2026
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.

1 participant