https://github.com/python/cpython/commit/5094690efd7f663f2e0c1a2a633d3344a0557095
commit: 5094690efd7f663f2e0c1a2a633d3344a0557095
branch: main
author: RaphaĆ«l Marinier <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-01-15T15:45:01-08:00
summary:

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.

files:
A Misc/NEWS.d/next/Library/2023-09-01-15-33-18.gh-issue-91539.xoNLEI.rst
M Lib/urllib/request.py

diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 1d03259b918c33..bca594420f6d9d 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2490,7 +2490,7 @@ def getproxies_environment():
     # select only environment variables which end in (after making lowercase) 
_proxy
     proxies = {}
     environment = []
-    for name in os.environ.keys():
+    for name in os.environ:
         # fast screen underscore position before more expensive case-folding
         if len(name) > 5 and name[-6] == "_" and name[-5:].lower() == "proxy":
             value = os.environ[name]
diff --git 
a/Misc/NEWS.d/next/Library/2023-09-01-15-33-18.gh-issue-91539.xoNLEI.rst 
b/Misc/NEWS.d/next/Library/2023-09-01-15-33-18.gh-issue-91539.xoNLEI.rst
new file mode 100644
index 00000000000000..a1af479459d755
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-09-01-15-33-18.gh-issue-91539.xoNLEI.rst
@@ -0,0 +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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to