Repository navigation
⚡ perf(plugin): defer dotenv loading - #341
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
94568d5 to
85798b0
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 pytest-env should not load the
.envparser for sessions that use only inline environment settings. The paired benchmark measured about 0.3 MiB less peak memory when importing the plugin on Python 3.14 and 3.15. Wall-time results varied under host load, so they do not establish a startup speedup.The plugin now loads python-dotenv when it reads an environment file. On Python 3.15, a lazy module declaration also delays
tomllibuntil TOML configuration needs it. The package root remains eager: deferring its version import showed no measurable gain. Lifeguard and flake8-lazy informed the import review.Benchmarks
Each block is one paired 60-run hyperfine comparison 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 Python 3.14 plugin run used the reverse command order to check the apparent slowdown in an earlier run.Python 3.15
Direct plugin import (
import pytest_env.plugin)pytest --helpPython 3.14
Direct plugin import (
import pytest_env.plugin)pytest --helpImport profile
The Python 3.15 diagrams come from
python -X importtime -c 'import pytest_env.plugin'and tuna. The before profile includesdotenv; the after profile does not. Most of the tree is pytest, which the plugin still needs at import time.Before
After