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 import #68

Merged
merged 5 commits into from
Sep 1, 2024

Conversation

hugovk
Copy link
Owner

@hugovk hugovk commented Sep 1, 2024

Saves about 15 ms, about twice as fast.

python --version
Python 3.13.0rc1python -X importtime -c "import pepotron" 2> import.log && tuna import.log

Before:

image

After:

image

Also move mypy from pre-commit to tox, because it's easier to run it against an installed project, so _version has been built.

hyperfine --warmup 32 \
--prepare "git checkout rm-importlib.metadata" 'python3 -c "import pepotron"' \
--prepare "git checkout main"                  'python3 -c "import    pepotron"'
Benchmark 1: python3 -c "import pepotron"
  Time (mean ± σ):      25.8 ms ±   1.1 ms    [User: 20.8 ms, System: 4.4 ms]
  Range (min … max):    24.6 ms …  30.3 ms    86 runs

Benchmark 2: python3 -c "import    pepotron"
  Time (mean ± σ):      41.6 ms ±   1.4 ms    [User: 34.2 ms, System: 6.8 ms]
  Range (min … max):    40.8 ms …  50.5 ms    47 runs

  Warning: The first benchmarking run for this command was significantly slower than the rest (50.5 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You are already using both the '--warmup' option as well as the '--prepare' option. Consider re-running the benchmark on a quiet system. Maybe it was a random outlier. Alternatively, consider increasing the warmup count.

Summary
  python3 -c "import pepotron" ran
    1.61 ± 0.09 times faster than python3 -c "import    pepotron"

@hugovk hugovk added the changelog: Changed For changes in existing functionality label Sep 1, 2024
@hugovk hugovk merged commit 353fa6b into main Sep 1, 2024
55 checks passed
@hugovk hugovk deleted the rm-importlib.metadata branch September 1, 2024 10:57
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