Christian Heimes <li...@cheimes.de> added the comment:

Please provide benchmarks and data for your claim that encodings.idna is a 
performance bottleneck.

encodings.idna is a simple, short module without state. On my system it takes 
about 0.15 msec to import the module. When unicodedata and stringprep aren't 
loaded yet, it still takes less than 0.5 msec. The stringprep and unicodedata 
modules are used by other modules, e.g. urllib parse. It's likely that any 
non-trivial program with network access has both imported already.

$ python3 -m timeit -s "import sys" "import encodings.idna; 
sys.modules.pop('encodings.idna'); sys.modules.pop('stringprep'); 
sys.modules.pop('unicodedata')"
500 loops, best of 5: 488 usec per loop


The IDNA codec performs additional verification of the input. You cannot 
replace it with a simple "try encode to ASCII" block:

>>> ("a"*65).encode('idna')
Traceback (most recent call last):
  File "/usr/lib64/python3.10/encodings/idna.py", line 167, in encode
    raise UnicodeError("label too long")
UnicodeError: label too long

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label too long)

----------
assignee: christian.heimes -> 
stage: patch review -> 

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46750>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to