René's URL Explorer Experiment


Title: gh-91539: improve performance of get_proxies_environment by eendebakpt · Pull Request #91566 · python/cpython · GitHub

Open Graph Title: gh-91539: improve performance of get_proxies_environment by eendebakpt · Pull Request #91566 · python/cpython

X Title: gh-91539: improve performance of get_proxies_environment by eendebakpt · Pull Request #91566 · python/cpython

Description: Improve performance of get_proxies_environment when there are many environment variables. Improvements depend on the number of environment variables, but the method is several times faster in this PR. Fixes #91539 Performance test details Results: 0.1634683609008789 0.024187326431274414 with import os import time import urllib.request if 0: os.environ={ f'{ii}': 1 for ii in range(8000)} os.environ.update({ f'{ii}_proxy': 1 for ii in range(30)}) def getproxies_environment(): """Return a dictionary of scheme -> proxy server URL mappings. Scan the environment for variables named _proxy; this seems to be the standard convention. If you need a different way, you can pass a proxies dictionary to the [Fancy]URLopener constructor. """ # in order to prefer lowercase variables, process environment in # two passes: first matches any, second pass matches lowercase only # select only environment variables which end in (after making lowercase) _proxy candidate_names = [name for name in os.environ.keys() if len(name)>5 and name[-6]=='_'] # fast selection of candidates environment = [(name, os.environ[name], name.lower()) for name in candidate_names if name[-6:].lower()=='_proxy'] proxies = {} for name, value, name_lower in environment: if value and name_lower[-6:] == '_proxy': proxies[name_lower[:-6]] = value # CVE-2016-1000110 - If we are running as CGI script, forget HTTP_PROXY # (non-all-lowercase) as it may be set from the web server by a "Proxy:" # header from the client # If "proxy" is lowercase, it will still be used thanks to the next block if 'REQUEST_METHOD' in os.environ: proxies.pop('http', None) for name, value, name_lower in environment: if name[-6:] == '_proxy': if value: proxies[name_lower[:-6]] = value else: proxies.pop(name_lower[:-6], None) return proxies nn=400 t0=time.time() for ii in range(nn): urllib.request.getproxies_environment() dt=time.time()-t0 print(dt) t0=time.time() for ii in range(nn): getproxies_environment() dt=time.time()-t0 print(dt) Issue: gh-91539

Open Graph Description: Improve performance of get_proxies_environment when there are many environment variables. Improvements depend on the number of environment variables, but the method is several times faster in this ...

X Description: Improve performance of get_proxies_environment when there are many environment variables. Improvements depend on the number of environment variables, but the method is several times faster in this ...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:420f728e-4a28-bd31-5e51-26242bdb3fc9
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC7EE:3671DE:E7F42A:13F1A0E:696A9128
html-safe-nonced34e506d5a4c00d8fecbb33983984e869b70abb59f6b353b079d0106e8aeca98
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0VFOjM2NzFERTpFN0Y0MkE6MTNGMUEwRTo2OTZBOTEyOCIsInZpc2l0b3JfaWQiOiI0Nzg1MjM5MjQ0ODMxMTAxMjI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac7728301858aa1383ea5f0bb055442c55089dd7473f6168a9599ca2b5066b0eef
hovercard-subject-tagpull_request:910787927
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/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/91566/files
twitter:imagehttps://avatars.githubusercontent.com/u/883786?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/883786?s=400&v=4
og:image:altImprove performance of get_proxies_environment when there are many environment variables. Improvements depend on the number of environment variables, but the method is several times faster in this ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4dd496afc954da9c207b2d9fbe86e3074619f565754aa1d9274aec30d9e5b8d7
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 full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release31496a13b80a2f6ad77d6c617ee2255a3545b539
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/91566/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F91566%2Ffiles
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%2F91566%2Ffiles
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%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/91566/files
Reloadhttps://github.com/python/cpython/pull/91566/files
Reloadhttps://github.com/python/cpython/pull/91566/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/91566/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k 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 Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/91566/files
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
orsenthilhttps://github.com/orsenthil
python:mainhttps://github.com/python/cpython/tree/main
eendebakpt:performance/getproxies_environmenthttps://github.com/eendebakpt/cpython/tree/performance/getproxies_environment
Conversation 14 https://github.com/python/cpython/pull/91566
Commits 26 https://github.com/python/cpython/pull/91566/commits
Checks 0 https://github.com/python/cpython/pull/91566/checks
Files changed https://github.com/python/cpython/pull/91566/files
Please reload this pagehttps://github.com/python/cpython/pull/91566/files
gh-91539: improve performance of get_proxies_environment https://github.com/python/cpython/pull/91566/files#top
Show all changes 26 commits https://github.com/python/cpython/pull/91566/files
42118e3 improve performance of get_proxies_environment when there are many en… eendebakpt Apr 15, 2022 https://github.com/python/cpython/pull/91566/commits/42118e3c2b68243df00a6d9fd03cd4495f496210
37ff8d9 📜🤖 Added by blurb_it. blurb-it[bot] Apr 15, 2022 https://github.com/python/cpython/pull/91566/commits/37ff8d9fb0ed143842351dd23ccdb9f443289299
b8de962 fix case of short env name eendebakpt Apr 15, 2022 https://github.com/python/cpython/pull/91566/commits/b8de96294e5c1b97f871266e4686318563bcf7cf
0f90945 Merge branch 'performance/getproxies_environment' of githubeendebakpt… eendebakpt Apr 15, 2022 https://github.com/python/cpython/pull/91566/commits/0f90945f5b8e6deeebefd3e4ed5bbc72252ce04f
336da07 fix formatting eendebakpt Apr 15, 2022 https://github.com/python/cpython/pull/91566/commits/336da07d16351a16f34d1458c9eeec3bddcc8034
cabeb47 fix whitespace eendebakpt Apr 15, 2022 https://github.com/python/cpython/pull/91566/commits/cabeb47cc0c556b0278704add666d1d52a751a5f
c581748 whitespace eendebakpt Apr 15, 2022 https://github.com/python/cpython/pull/91566/commits/c58174891dc82c7f6a6bbe8a0a03d5b5087b9072
4217396 Merge branch 'main' into performance/getproxies_environment eendebakpt May 11, 2022 https://github.com/python/cpython/pull/91566/commits/421739626155b2addcded1b113299ebcd9c5c6c8
0055604 Merge branch 'main' into performance/getproxies_environment eendebakpt May 13, 2022 https://github.com/python/cpython/pull/91566/commits/0055604655d981525efa914d8c16a26eb2675953
869fa9a Merge branch 'main' into performance/getproxies_environment eendebakpt May 17, 2022 https://github.com/python/cpython/pull/91566/commits/869fa9a558b261d8e7446c3c53a7a5d6eb35c5fe
dba0414 Update Lib/urllib/request.py eendebakpt May 18, 2022 https://github.com/python/cpython/pull/91566/commits/dba04145c2e9dfb35f5794eeeeed882e460ceab7
76f16ca Update Lib/urllib/request.py eendebakpt May 18, 2022 https://github.com/python/cpython/pull/91566/commits/76f16ca13b4d7d793386c4fb3e0e66fcaf9ea9ec
d3feb07 Update Lib/urllib/request.py eendebakpt May 18, 2022 https://github.com/python/cpython/pull/91566/commits/d3feb07e1d69255087f92b82fdafe7bc37855975
b9ab037 Update Lib/urllib/request.py eendebakpt May 18, 2022 https://github.com/python/cpython/pull/91566/commits/b9ab037c9ab6a046f5ef2c5db243841e11ffd134
f961505 whitespace eendebakpt May 18, 2022 https://github.com/python/cpython/pull/91566/commits/f96150587daa573c819101aa361b6f7a677bb890
36e5497 Update Misc/NEWS.d/next/Library/2022-04-15-11-29-38.gh-issue-91539.7W… eendebakpt May 18, 2022 https://github.com/python/cpython/pull/91566/commits/36e5497a9f6d1dcda4d2a7b1ed851e8be0bd31af
ca4fbd4 Update Lib/urllib/request.py eendebakpt May 18, 2022 https://github.com/python/cpython/pull/91566/commits/ca4fbd40b31d01f657ebfda3979d050afb7505d6
77cceab Merge branch 'main' into performance/getproxies_environment eendebakpt May 31, 2022 https://github.com/python/cpython/pull/91566/commits/77cceabc6a6393c75a99e99574d57392e15bced2
9687ebb Merge branch 'main' into performance/getproxies_environment eendebakpt Jun 12, 2022 https://github.com/python/cpython/pull/91566/commits/9687ebb7c96d1e7b4b94dd129de17d0a61b0e6f6
3bf6f63 Merge branch 'main' into performance/getproxies_environment eendebakpt Jun 24, 2022 https://github.com/python/cpython/pull/91566/commits/3bf6f63d15a52917b675a9cd9170ad7855239168
fc36faa Merge branch 'main' into performance/getproxies_environment eendebakpt Jul 2, 2022 https://github.com/python/cpython/pull/91566/commits/fc36faa21a4e28c3f77a7587cf26e51b6c163492
b6d866f Merge branch 'main' into performance/getproxies_environment eendebakpt Jul 16, 2022 https://github.com/python/cpython/pull/91566/commits/b6d866f88e0138d94c9844a05de79df60a51b860
f40e0dc Merge branch 'main' into performance/getproxies_environment eendebakpt Jul 26, 2022 https://github.com/python/cpython/pull/91566/commits/f40e0dc9965388483b7eb676b3703974d979a98f
41410da Merge branch 'main' into performance/getproxies_environment eendebakpt Aug 2, 2022 https://github.com/python/cpython/pull/91566/commits/41410daadf0809989618f7a09507ba49a439957f
41b72c6 Merge branch 'main' into performance/getproxies_environment eendebakpt Sep 11, 2022 https://github.com/python/cpython/pull/91566/commits/41b72c62a6fe0002e484dd531604e479c38cf030
9db1103 Merge branch 'main' into performance/getproxies_environment eendebakpt Sep 26, 2022 https://github.com/python/cpython/pull/91566/commits/9db11030dff87d4bb6fe12bd41011754bdaf2aa2
Clear filters https://github.com/python/cpython/pull/91566/files
Please reload this pagehttps://github.com/python/cpython/pull/91566/files
Please reload this pagehttps://github.com/python/cpython/pull/91566/files
request.py https://github.com/python/cpython/pull/91566/files#diff-1b72fd8dc0aaa51a5ba3af938d3e3bdea8ab5635c0c2d9e098f9825f5b47b03f
2022-04-15-11-29-38.gh-issue-91539.7WgVuA.rst https://github.com/python/cpython/pull/91566/files#diff-663ddf283529a05f076ac534aff0aca572a676af19f0cdb7e2a50870a6ad5a38
Lib/urllib/request.pyhttps://github.com/python/cpython/pull/91566/files#diff-1b72fd8dc0aaa51a5ba3af938d3e3bdea8ab5635c0c2d9e098f9825f5b47b03f
View file https://github.com/eendebakpt/cpython/blob/9db11030dff87d4bb6fe12bd41011754bdaf2aa2/Lib/urllib/request.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/91566/{{ revealButtonHref }}
https://github.com/python/cpython/pull/91566/files#diff-1b72fd8dc0aaa51a5ba3af938d3e3bdea8ab5635c0c2d9e098f9825f5b47b03f
Please reload this pagehttps://github.com/python/cpython/pull/91566/files
https://github.com/python/cpython/pull/91566/files#diff-1b72fd8dc0aaa51a5ba3af938d3e3bdea8ab5635c0c2d9e098f9825f5b47b03f
Misc/NEWS.d/next/Library/2022-04-15-11-29-38.gh-issue-91539.7WgVuA.rsthttps://github.com/python/cpython/pull/91566/files#diff-663ddf283529a05f076ac534aff0aca572a676af19f0cdb7e2a50870a6ad5a38
View file https://github.com/eendebakpt/cpython/blob/9db11030dff87d4bb6fe12bd41011754bdaf2aa2/Misc/NEWS.d/next/Library/2022-04-15-11-29-38.gh-issue-91539.7WgVuA.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/91566/{{ revealButtonHref }}
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.