Skip to content

Commit 9717187

Browse files
RaphaelMarinieraisk
authored andcommitted
pythongh-91539: Small performance improvement of urrlib.request.getproxies_environment() (python#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 a7faebe commit 9717187

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Lib/urllib/request.py

+1-1
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]
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)