Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate __version__ at build to avoid slow importlib.metadata #446

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

hugovk
Copy link
Owner

@hugovk hugovk commented Aug 6, 2024

With Python 3.12.4:

python -X importtime -c "import pypistats" 2> import.log && tuna import.log

Cuts out the 23ms importlib.metadata import.

The call itself can also be slow, for example, 15ms in some venvs.

main

image
hyperfine --warmup 8 "pypistats --version"
Benchmark 1: pypistats --version
  Time (mean ± σ):      57.2 ms ±   3.3 ms    [User: 44.6 ms, System: 10.9 ms]
  Range (min … max):    51.7 ms …  72.8 ms    48 runs

PR

image
hyperfine --warmup 8 "pypistats --version"
Benchmark 1: pypistats --version
  Time (mean ± σ):      37.4 ms ±   2.7 ms    [User: 29.0 ms, System: 7.3 ms]
  Range (min … max):    34.6 ms …  55.4 ms    74 runs

And update some config.

@hugovk hugovk added the changelog: Changed For changes in existing functionality label Aug 6, 2024
@hugovk hugovk merged commit 0c6649e into main Aug 6, 2024
71 checks passed
@hugovk hugovk deleted the version-file branch August 6, 2024 14:46
@hugovk hugovk changed the title Generate __version__ at build to avoid slow importlib.metadata import Generate __version__ at build to avoid slow importlib.metadata Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: Changed For changes in existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant