René's URL Explorer Experiment


Title: gh-130167: Improve speed of `inspect.formatannotation` by replacing `re` by donbarbos · Pull Request #130242 · python/cpython · GitHub

Open Graph Title: gh-130167: Improve speed of `inspect.formatannotation` by replacing `re` by donbarbos · Pull Request #130242 · python/cpython

X Title: gh-130167: Improve speed of `inspect.formatannotation` by replacing `re` by donbarbos · Pull Request #130242 · python/cpython

Description: timeit benchmark with my script: inspect_bench.py: import re import timeit from typing import List, Dict, Any, Union def old_format_annotation(annotation): if getattr(annotation, "__module__", None) == "typing": def repl(match): text = match.group() return text.removeprefix("typing.") return re.sub(r"[\w\.]+", repl, repr(annotation)) return repr(annotation) def new_format_annotation(annotation): if getattr(annotation, "__module__", None) == "typing": return (repr(annotation) .replace(".typing.", "@TYPING@") .replace("typing.", "") .replace("@TYPING@", ".typing.")) return repr(annotation) old_time = timeit.timeit(lambda: old_format_annotation(Union[List[str], Dict[str, Any]]), number=100_000) new_time = timeit.timeit(lambda: new_format_annotation(Union[List[str], Dict[str, Any]]), number=100_000) print(f"Old version (re.sub): {old_time:.6f}s") print(f"New version (.replace()): {new_time:.6f}s") print(f"Difference: {old_time / new_time:.2f}x") Result: 2.0s -> 1.18s = x1.74 as fast $ ./python -B inspect_bench.py Old version (re.sub): 2.043900s New version (.replace()): 1.175867s Difference: 1.74x ✔️ This was also the only use of re in module so i got rid of the import Issue: gh-130167

Open Graph Description: timeit benchmark with my script: inspect_bench.py: import re import timeit from typing import List, Dict, Any, Union def old_format_annotation(annotation): if getattr(annotation, "__modul...

X Description: timeit benchmark with my script: inspect_bench.py: import re import timeit from typing import List, Dict, Any, Union def old_format_annotation(annotation): if getattr(annotation, "__m...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/commits/:range(.:format)
route-controllerpull_requests
route-actioncommits
fetch-noncev2:51c1ad64-cf86-5154-7ce7-ffa7434a4b6f
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAF70:D4DD7:780D6E8:A3915D0:69961175
html-safe-nonce0447b3ca2edc2963ebccfd06ab9e523129c3ee070fe4de55aa7d83009d3a5f80
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjcwOkQ0REQ3Ojc4MEQ2RTg6QTM5MTVEMDo2OTk2MTE3NSIsInZpc2l0b3JfaWQiOiI4MTcyMTE3NDQ3OTEyMzI5NTg5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac04131547cb2b0c1f57902c1279929a0497f765af671ebd846871551ad523386f
hovercard-subject-tagpull_request:2340808632
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/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
twitter:imagehttps://avatars.githubusercontent.com/u/47272787?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/47272787?s=400&v=4
og:image:alttimeit benchmark with my script: inspect_bench.py: import re import timeit from typing import List, Dict, Any, Union def old_format_annotation(annotation): if getattr(annotation, "__modul...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None7490a2fd98baca866acf503b81aa249491b42e5b4bab7f7a2801be81175c8845
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
release48a904441630875f5985de713035046dc65cc94c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F130242%2Fcommits%2F0ecf16f063afc6760cc625d7270f4381d72248c4
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%2F130242%2Fcommits%2F0ecf16f063afc6760cc625d7270f4381d72248c4
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/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
Reloadhttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
Reloadhttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.6k 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
donbarboshttps://github.com/donbarbos
python:mainhttps://github.com/python/cpython/tree/main
donbarbos:improve-inspect-speedhttps://github.com/donbarbos/cpython/tree/improve-inspect-speed
Conversation 6 https://github.com/python/cpython/pull/130242
Commits 8 https://github.com/python/cpython/pull/130242/commits
Checks 35 https://github.com/python/cpython/pull/130242/checks
Files changed https://github.com/python/cpython/pull/130242/files
Please reload this pagehttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
gh-130167: Improve speed of inspect.formatannotation by replacing re https://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4#top
Show all changes 8 commits https://github.com/python/cpython/pull/130242/files
ef19ae6 Improve speed of inspect.formatannotation by replacing re donbarbos Feb 17, 2025 https://github.com/python/cpython/pull/130242/commits/ef19ae67fc2b65bebd0095dfb7b800782254a89d
7dc08b7 Merge branch 'main' into improve-inspect-speed donbarbos Feb 18, 2025 https://github.com/python/cpython/pull/130242/commits/7dc08b7385a8c3f2f554e9836220f2a930d3f449
d9480c7 Add blurb donbarbos Feb 18, 2025 https://github.com/python/cpython/pull/130242/commits/d9480c74108943493f7047d5190b67181bba6795
ab85241 Update NEWS.d entry markup donbarbos Feb 18, 2025 https://github.com/python/cpython/pull/130242/commits/ab852415efe9e6690d75303047e793bf5be9a80a
f48b2ed Merge branch 'main' into improve-inspect-speed donbarbos Mar 27, 2025 https://github.com/python/cpython/pull/130242/commits/f48b2edc5d1455c650ff6317039c10ec5c63f2be
3c1c4b7 Update rst syntax in News entry donbarbos Mar 27, 2025 https://github.com/python/cpython/pull/130242/commits/3c1c4b74205652b59804bf27f81caa6824715b85
1bfbe05 Update 2025-02-18-05-04-13.gh-issue-130167.aOgAz_.rst donbarbos Mar 27, 2025 https://github.com/python/cpython/pull/130242/commits/1bfbe05fd1057fc5dfa3fcba44332f15db37d90b
0ecf16f Remove implementation detail from News entry donbarbos Apr 30, 2025 https://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
Clear filters https://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
Please reload this pagehttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
Please reload this pagehttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
Prev https://github.com/python/cpython/pull/130242/commits/1bfbe05fd1057fc5dfa3fcba44332f15db37d90b
Please reload this pagehttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
https://github.com/donbarbos
donbarboshttps://github.com/python/cpython/commits?author=donbarbos
Misc/NEWS.d/next/Library/2025-02-18-05-04-13.gh-issue-130167.aOgAz_.rsthttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4#diff-0333c64cd3b74587c7a48e53ac521c089eab1ee91b0e637e4fa1a97bc75e5d7a
View file https://github.com/python/cpython/blob/0ecf16f063afc6760cc625d7270f4381d72248c4/Misc/NEWS.d/next/Library/2025-02-18-05-04-13.gh-issue-130167.aOgAz_.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/130242/commits/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/cpython/pull/130242/commits/0ecf16f063afc6760cc625d7270f4381d72248c4
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.