Repository navigation
⚡ perf(import): defer pyproject-api modules - #377
Merged
Merged
Conversation
Importing the public API and opening CLI help load frontend dependencies before either path uses them on Python 3.15. Defer eligible modules until their operations run.
gaborbernat
marked this pull request as draft
November 18, 2026 07:46
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.
Importing
pyproject-apior opening its CLI help previously loaded frontend modules that those paths did not use. In a paired 60-run Python 3.15 hyperfine benchmark, package import measured 39.9 → 7.5 ms.The public API, CLI, frontend transport, and backend script declare eligible lazy imports, so build operations load their dependencies when called. flake8-lazy checks those declarations. The backend script retains Python 2.7 compatible syntax, and earlier Python versions ignore the declarations.
Benchmarks
Each workload and Python version has one
hyperfine 2.0.0 --warmup 5 --runs 60 --metrics time_wall_clock:ms,memory_peak_resident:MiBinvocation comparing the PR with its merge base. Raw output reports wall time and peak resident memory. Both commands used the same interpreter and dependencies in a tox environment;PYTHONPATHselected the source tree. Python 3.14 ignores the lazy declarations.Python 3.15
Package import
CLI help
Python 3.14
Package import
CLI help
Import-time profile
Lifeguard scanned the source tree with
--python-version 3.15. I also imported 6 modules separately withpython -X importtime.These are one-run cumulative import timings for the modules with the largest reductions:
pyproject_api._backendThe Python 3.15 package import diagrams use
python -X importtime -c "import pyproject_api" 2> import.logand tuna.Before
After