Repository navigation
⚡ perf(import): defer directive helpers - #417
Merged
Merged
Conversation
gaborbernat
marked this pull request as ready for review
November 18, 2026 22:28
gaborbernat
force-pushed
the
perf/lazy-imports
branch
from
November 18, 2026 23:18
61052c8 to
df1b97f
Compare
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.
Loading the Sphinx directive now takes less time and memory on Python 3.15. In a paired 60-run benchmark, importing the directive module fell from 83.8 to 70.4 ms and peak memory from 35.9 to 31.8 MiB. Python 3.14 showed no material change.
The extension keeps the imports needed to register its directive eager and defers helpers used only while rendering CLI documentation. Its package root is already light; the new lazy declaration there covers only the version module. Lifeguard and flake8-lazy guided the module review. The
sys.modulesaccess and logger initialization remain eager.Benchmarks
Each block is one paired 60-run hyperfine invocation with
--warmup 5 --metrics time_wall_clock:ms,memory_peak_resident:MiB. Both commands used the same tox interpreter and dependencies, withPYTHONPATHselecting the merge-base or PR source tree. The small package-root differences are below the run-to-run variation.Python 3.15
Package root (
import sphinx_argparse_cli)Directive module (
import sphinx_argparse_cli._logic)Python 3.14
Package root (
import sphinx_argparse_cli)Directive module (
import sphinx_argparse_cli._logic)Import profile
These Python 3.15 diagrams come from
python -X importtime -c 'import sphinx_argparse_cli._logic'and tuna.Before
After