René's URL Explorer Experiment


Title: gh-143658: importlib.metadata: Use `str.translate` to improve performance of `importlib.metadata.Prepared.normalized` by hugovk · Pull Request #143660 · python/cpython · GitHub

Open Graph Title: gh-143658: importlib.metadata: Use `str.translate` to improve performance of `importlib.metadata.Prepared.normalized` by hugovk · Pull Request #143660 · python/cpython

X Title: gh-143658: importlib.metadata: Use `str.translate` to improve performance of `importlib.metadata.Prepared.normalized` by hugovk · Pull Request #143660 · python/cpython

Description: We can apply @henryiii's improvement to packaging in pypa/packaging#1030 (see also https://iscinumpy.dev/post/packaging-faster/) to improve the performance of canonicalize_name and make it ~3.7 times faster. Benchmark Run Prepared.normalize(n) on every name in PyPI: # benchmark_names_stdlib.py import sqlite3 import timeit from importlib.metadata import Prepared # Get data with: # curl -L https://github.com/pypi-data/pypi-json-data/releases/download/latest/pypi-data.sqlite.gz | gzip -d > pypi-data.sqlite # Or ues pre-cached files from: # https://gist.github.com/hugovk/efdbee0620cc64df7b405b52cf0b6e42 CACHE_FILE = "/tmp/bench/names.txt" DB_FILE = "/tmp/bench/pypi-data.sqlite" try: with open(CACHE_FILE) as f: TEST_ALL_NAMES = [line.rstrip("\n") for line in f] except FileNotFoundError: TEST_ALL_NAMES = [] with sqlite3.connect(DB_FILE) as conn: with open(CACHE_FILE, "w") as cache: for (name,) in conn.execute("SELECT name FROM projects"): if name: TEST_ALL_NAMES.append(name) cache.write(name + "\n") def bench(): for n in TEST_ALL_NAMES: Prepared.normalize(n) if __name__ == "__main__": print(f"Loaded {len(TEST_ALL_NAMES):,} names") t = timeit.timeit("bench()", globals=globals(), number=1) print(f"Time: {t:.4f} seconds") Benchmark data can be found at https://gist.github.com/hugovk/efdbee0620cc64df7b405b52cf0b6e42 Before With optimisations: ❯ ./python.exe benchmark_names_stdlib.py Loaded 8,344,947 names Time: 5.1483 seconds After ❯ ./python.exe benchmark_names_stdlib.py Loaded 8,344,947 names Time: 1.3754 seconds 3.7 times faster. Issue: gh-143658

Open Graph Description: We can apply @henryiii's improvement to packaging in pypa/packaging#1030 (see also https://iscinumpy.dev/post/packaging-faster/) to improve the performance of canonicalize_name and make it ~3.7...

X Description: We can apply @henryiii's improvement to packaging in pypa/packaging#1030 (see also https://iscinumpy.dev/post/packaging-faster/) to improve the performance of canonicalize_name and make it ...

Opengraph URL: https://github.com/python/cpython/pull/143660

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/commits/:range(.:format)
route-controllerpull_requests
route-actioncommits
fetch-noncev2:c4236851-2ef2-ac39-160e-21c285295182
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA8E4:24D925:450544E:5BDC9AD:69958E61
html-safe-nonce509e1a40e1a7f5bc2ce86aa4a9f3d9a765524c2377b8ac27c2c859a2ba8229ca
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEU0OjI0RDkyNTo0NTA1NDRFOjVCREM5QUQ6Njk5NThFNjEiLCJ2aXNpdG9yX2lkIjoiODY5OTQxMzQzODk5NTQ2Nzg3MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac51571ee701e8846a08b6aefbc908a4a3836f20a4325dc25ef8bc1be8a796768d
hovercard-subject-tagpull_request:3162057244
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/commits
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
twitter:imagehttps://avatars.githubusercontent.com/u/1324225?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1324225?s=400&v=4
og:image:altWe can apply @henryiii's improvement to packaging in pypa/packaging#1030 (see also https://iscinumpy.dev/post/packaging-faster/) to improve the performance of canonicalize_name and make it ~3.7...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4bd759bc5f83244e2a0de29b937365905c0fefd238b6f077c24a49830375b4df
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release84938599335a8dc49305d1a140adf6e19877540a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F143660%2Fcommits%2F7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F143660%2Fcommits%2F7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Fcommits&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
Reloadhttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
Reloadhttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.5k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
hugovkhttps://github.com/hugovk
python:mainhttps://github.com/python/cpython/tree/main
hugovk:3.15-importlib.metadata-canonicalize_namehttps://github.com/hugovk/cpython/tree/3.15-importlib.metadata-canonicalize_name
Conversation 23 https://github.com/python/cpython/pull/143660
Commits 7 https://github.com/python/cpython/pull/143660/commits
Checks 48 https://github.com/python/cpython/pull/143660/checks
Files changed 3 https://github.com/python/cpython/pull/143660/files
gh-143658: importlib.metadata: Use str.translate to improve performance of importlib.metadata.Prepared.normalized https://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000#top
Show all changes 7 commits https://github.com/python/cpython/pull/143660/files
76e2272 Use translate to improve performance of canonicalize_name hugovk Jan 10, 2026 https://github.com/python/cpython/pull/143660/commits/76e227242e311d068eb24e65c86253d08c7ffcf0
00c76fc Add blurb hugovk Jan 10, 2026 https://github.com/python/cpython/pull/143660/commits/00c76fc7451ccb294bd890244aa17116239175e3
c1bb3cc Improve blurb hugovk Jan 10, 2026 https://github.com/python/cpython/pull/143660/commits/c1bb3ccfc0dfe93b644356e1e54ab2e8bc90e661
0eae552 Improve comment hugovk Jan 10, 2026 https://github.com/python/cpython/pull/143660/commits/0eae55202f7a2413637e39df83c0953a06ddfae3
1657880 Add tests for Prepared.normalize hugovk Jan 10, 2026 https://github.com/python/cpython/pull/143660/commits/1657880f0fad56be0483d6d1d6c9d9e66b21e1ee
ee0e6aa Fix lint hugovk Jan 10, 2026 https://github.com/python/cpython/pull/143660/commits/ee0e6aa3b276de216a760502fd7060ec878385d9
7b7f9a8 Add extra test case with repeated separator hugovk Jan 10, 2026 https://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
Clear filters https://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
Please reload this pagehttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
Please reload this pagehttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
Prev https://github.com/python/cpython/pull/143660/commits/ee0e6aa3b276de216a760502fd7060ec878385d9
Please reload this pagehttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
https://github.com/hugovk
https://github.com/johnslavik
hugovkhttps://github.com/python/cpython/commits?author=hugovk
johnslavikhttps://github.com/python/cpython/commits?author=johnslavik
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L507
Lib/test/test_importlib/metadata/test_api.pyhttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000#diff-80486327043c2bbdd6af50e72788bb799270e0bff19633b77cefbc99fe163059
View file https://github.com/hugovk/cpython/blob/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000/Lib/test/test_importlib/metadata/test_api.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/143660/commits/{{ revealButtonHref }}
https://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000#diff-80486327043c2bbdd6af50e72788bb799270e0bff19633b77cefbc99fe163059
Please reload this pagehttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
https://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000#diff-80486327043c2bbdd6af50e72788bb799270e0bff19633b77cefbc99fe163059
Please reload this pagehttps://github.com/python/cpython/pull/143660/commits/7b7f9a8773cc12f54ff987e6c6fa8ffcbf3a6000
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.