[issue30276] import hashlib makes many programs slow

2017-05-12 Thread Bernhard M. Wiedemann
Bernhard M. Wiedemann added the comment: Tracking this in https://bugzilla.opensuse.org/show_bug.cgi?id=1038906 now. It turned out to be a problem with (our?) openssl-1.0.2 which Debian stable does not have yet and Debian/9 (stretch) has openssl-1.1.0 without this problem The nicest

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread Bernhard M. Wiedemann
Bernhard M. Wiedemann added the comment: getting to a similar size on Debian, so I'll move this into the openSUSE bugtracker to find out why it is so slow there. -- resolution: -> third party stage: -> resolved status: open -> closed ___ Python

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread STINNER Victor
STINNER Victor added the comment: I ran a quick benchmark on my laptop, Fedora 25: haypo@selma$ python3 -m perf command -o ref.json -- python3 -c 'pass' && python3 -m perf command -o hashlib.json -- python3 -c 'import hashlib' && python3 -m perf compare_to ref.json hashlib.json --table

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread Christian Heimes
Christian Heimes added the comment: If import of hashlib is slowed down by OpenSSL, then import of ssl module will be even slower. Am 5. Mai 2017 17:57:41 MESZ schrieb "Bernhard M. Wiedemann" : > >Bernhard M. Wiedemann added the comment: > >This might work in some

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread Bernhard M. Wiedemann
Bernhard M. Wiedemann added the comment: This might work in some places, but if you look at real-world users like urllib3/util/ssl_.py > from hashlib import md5, sha1, sha256 or twisted/words/protocols/jabber/xmlstream.py > from hashlib import sha1 It would probably not need any openssl at

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread STINNER Victor
STINNER Victor added the comment: > the urandom calls themselves are not slow, but probably the processing in > between. Can't that be done on demand on first use? If the time is spent on loading OpenSSL, maybe you should try to import hashlib on demand? --

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread Bernhard M. Wiedemann
Bernhard M. Wiedemann added the comment: I'm running openSUSE Tumbleweed with python-2.7.13 and python3-3.6.1 on an Intel Pentium N3530 with linux-4.10.12 There the total time of the "import _hashlib" oneliner varies between 100 and 250 ms (python3 is a bit slower and the machine is slower when

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread Christian Heimes
Christian Heimes added the comment: I rather suspect it's OpenSSL. It takes a bit to load and initialize libcrypto.so. On my system it takes about 17ms to import _hashlib. There is nothing we can do about it in CPython. -- ___ Python tracker

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread STINNER Victor
STINNER Victor added the comment: What is your OS? Which kind of computer is it? I'm surprised that you noticed open calls on /dev/urandom, it should be very quick, no? -- ___ Python tracker

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread STINNER Victor
STINNER Victor added the comment: What is your Python version? It looks like an old version. -- ___ Python tracker ___

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread Christian Heimes
Christian Heimes added the comment: I cannot reproduce the open /dev/urandom calls locally. You seem to be running an old Python version and/or old Kernel. Python prefers getrandom() over /dev/urandom. The urandom code caches the fd for /dev/urandom. $ strace ./python -c 'import hashlib' 2>&1

[issue30276] import hashlib makes many programs slow

2017-05-05 Thread Bernhard M. Wiedemann
Bernhard M. Wiedemann added the comment: traced it down a bit further. nearly all that time is spent in import _hashlib which probably means, it is spent in functions like PyInit__hashlib in Modules/_hashopenssl.c I can see in strace that after loading libssl, libcrypto and libz, it calls

[issue30276] import hashlib makes many programs slow

2017-05-04 Thread Bernhard M. Wiedemann
New submission from Bernhard M. Wiedemann: Steps to Reproduce: echo import hashlib > test.py time python -m cProfile -s tottime test.py 2>&1 | head Actual Results: shows 27ms spent in hashlib.py The problem goes away when dropping everything after line 133 in hashlib.py see also issue 21288