Skip to content

Commit 5094690

Browse files
gh-91539: Small performance improvement of urrlib.request.getproxies_environment() (#108771)
Small performance improvement of getproxies_environment() when there are many environment variables. In a benchmark with 5k environment variables not related to proxies, and 5 specifying proxies, we get a 10% walltime improvement.
1 parent 4f24b92 commit 5094690

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Lib/urllib/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,7 @@ def getproxies_environment():
24902490
# select only environment variables which end in (after making lowercase) _proxy
24912491
proxies = {}
24922492
environment = []
2493-
for name in os.environ.keys():
2493+
for name in os.environ:
24942494
# fast screen underscore position before more expensive case-folding
24952495
if len(name) > 5 and name[-6] == "_" and name[-5:].lower() == "proxy":
24962496
value = os.environ[name]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Small (10 - 20%) and trivial performance improvement of :func:`urrlib.request.getproxies_environment`, typically useful when there are many environment variables to go over.

0 commit comments

Comments
 (0)