Repository navigation
⚡ perf(import): defer unused SBOM modules - #29
Merged
Merged
Conversation
Loading the public package and CLI help imports much of the build and validation stack on Python 3.15. Defer modules until their functionality is used, while keeping the Hatch hook's dependency check eager.
Documentation build overview
|
gaborbernat
marked this pull request as draft
November 18, 2026 07:46
gaborbernat
marked this pull request as ready for review
November 18, 2026 08:45
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
python-sbomor opening its CLI help previously loaded modules for SBOM generation, validation, and build backends that those paths did not use. In a paired 60-run Python 3.15 hyperfine benchmark, package import measured 37.7 → 7.5 ms.The public API, CLI, and backend modules declare imports eligible for Python 3.15 lazy loading, so generation, validation, and build paths load their dependencies when used. Earlier Python versions ignore these declarations. flake8-lazy keeps them aligned with the imports. The Hatch entry point still checks for
hatchlingwhen imported, since callers rely on that dependency error appearing immediately.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 59 modules separately withpython -X importtime.These are one-run cumulative import timings for the modules with the largest reductions:
python_sbom.setuptoolspython_sbom._validate._schemaspython_sbom._cli._archiveThe Python 3.15 package import diagrams use
python -X importtime -c "import python_sbom" 2> import.logand tuna.Before
After