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 #142

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

hugovk
Copy link
Owner

@hugovk hugovk commented Aug 31, 2024

Like hugovk/tinytext#195.

With Python 3.13.0rc1:

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

Cuts 7 ms by removing the importlib.metadata import.

main

image

PR

image

hyperfine

hyperfine --warmup 32 \
--prepare "git checkout rm-importlib.metadata" 'python3 -c "import em_keyboard"' \
--prepare "git checkout main"                  'python3 -c "import    em_keyboard"'
Benchmark 1: python3 -c "import em_keyboard"
  Time (mean ± σ):      37.4 ms ±   1.0 ms    [User: 30.2 ms, System: 6.3 ms]
  Range (min … max):    36.1 ms …  42.8 ms    64 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    em_keyboard"
  Time (mean ± σ):      47.2 ms ±   8.4 ms    [User: 37.7 ms, System: 7.7 ms]
  Range (min … max):    44.8 ms … 105.0 ms    52 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 em_keyboard" ran
    1.26 ± 0.23 times faster than python3 -c "import    em_keyboard"

Copy link

codecov bot commented Aug 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.96%. Comparing base (c2b1faf) to head (8ccef3c).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #142      +/-   ##
==========================================
- Coverage   98.49%   93.96%   -4.53%     
==========================================
  Files           2        2              
  Lines         199      199              
==========================================
- Hits          196      187       -9     
- Misses          3       12       +9     
Flag Coverage Δ
macos-latest 91.95% <100.00%> (-2.52%) ⬇️
ubuntu-latest 93.96% <100.00%> (ø)
windows-latest ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hugovk hugovk added the changelog: Changed For changes in existing functionality label Aug 31, 2024
@hugovk hugovk merged commit a4d368d into main Aug 31, 2024
54 of 57 checks passed
@hugovk hugovk deleted the rm-importlib.metadata branch August 31, 2024 18:55
@hugovk hugovk added changelog: Fixed For any bug fixes changelog: Changed For changes in existing functionality and removed changelog: Changed For changes in existing functionality changelog: Fixed For any bug fixes labels Aug 31, 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