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

Speedup x 2.15: Generate __version__ at build to avoid slow importlib.metadata import #24

Merged
merged 3 commits into from
Sep 10, 2024

Conversation

hugovk
Copy link
Owner

@hugovk hugovk commented Sep 10, 2024

Like hugovk/tinytext#195.

With Python 3.13.0rc2:

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

main

image

PR

image

hyperfine

hyperfine --warmup 32 \
--prepare "git checkout rm-importlib.metadata" 'python3 -c "import linkotron # PR"' \
--prepare "git checkout main"                  'python3 -c "import linkotron # main"'
Benchmark 1: python3 -c "import linkotron # PR"
  Time (mean ± σ):      18.6 ms ±   1.3 ms    [User: 14.8 ms, System: 3.4 ms]
  Range (min … max):    17.7 ms …  25.6 ms    106 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs.

Benchmark 2: python3 -c "import linkotron # main"
  Time (mean ± σ):      40.0 ms ±   1.3 ms    [User: 32.5 ms, System: 6.9 ms]
  Range (min … max):    38.9 ms …  47.3 ms    60 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs.

Summary
  python3 -c "import linkotron # PR" ran
    2.15 ± 0.16 times faster than python3 -c "import linkotron # main"

Also move mypy from pre-commit to tox, so it runs when the version file has been generated.

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