Repository navigation
⚡ perf(import): defer platformdirs imports - #722
Open
gaborbernat wants to merge 2 commits into
Open
gaborbernat wants to merge 2 commits into
gaborbernat wants to merge 2 commits into
Conversation
Declare imports safe to defer on Python 3.15 and check new imports with flake8-lazy. Keep cache and patch targets eager.
gaborbernat
marked this pull request as ready for review
November 18, 2026 08:45
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Common platformdirs calls previously loaded helpers they did not use. In a paired 60-run Python 3.15 hyperfine benchmark, package import measured 25.1 → 17.3 ms.
Module declarations defer eligible imports until needed, and flake8-lazy checks future imports. Android cache handling and Unix runtime helpers stay eager because callers can observe and patch those imports. Earlier Python versions keep eager imports.
Benchmarks
hyperfine 2.0.0 --warmup 5 --runs 60compared the PR with its merge base. Each pair used the same interpreter and dependencies in a tox environment;PYTHONPATHselected the source tree. Python 3.14 does not enable lazy imports. These wall times include process startup. The Python 3.14 CLI help comparison has high variation, so its apparent slowdown is inconclusive.Python 3.15
import:help:Python 3.14
import:help:Import-time profile
Lifeguard scanned the source tree with
--python-version 3.15. I also imported 13 modules separately withpython -X importtime.These are one-run cumulative import timings for the modules with the largest reductions:
platformdirs.androidplatformdirs.windowsplatformdirs.macosThe Python 3.15 package import diagrams use
python -X importtime -c "import platformdirs" 2> import.logand tuna.Before
After