Author serhiy.storchaka
Recipients brett.cannon, eric.smith, eric.snow, ncoghlan, pitrou, serhiy.storchaka
Date 2016-06-19.12:01:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1466337669.2.0.193833385692.issue22557@psf.upfronthosting.co.za>
In-reply-to
Content
Fixed bugs making test_importlib failing.

Microbenchmark results on faster machine:

$ ./python -m timeit 'import locale'
Unpatched:  1000000 loops, best of 3: 0.839 usec per loop
Patched:    10000000 loops, best of 3: 0.176 usec per loop

$ ./python -m timeit 'import os.path'
Unpatched:  100000 loops, best of 3: 2.02 usec per loop
Patched:    1000000 loops, best of 3: 1.77 usec per loop

$ ./python -m timeit 'from locale import getlocale'
Unpatched:  100000 loops, best of 3: 3.69 usec per loop
Patched:    100000 loops, best of 3: 3.39 usec per loop

And it looks to me that there is a bug in existing code (opened separate issue27352).

0.839 usec is not very slow by CPython's standards, but is equal to about 50 assignments to local variable, 15 attribute revolvings or 5 simple function calls. If some module is optionally needed in fast function, the overhead of local import can be significant. We can lazily initialize global variable (the second example in msg228561), but this code looks more cumbersome.
History
Date User Action Args
2016-06-19 12:01:09serhiy.storchakasetrecipients: + serhiy.storchaka, brett.cannon, ncoghlan, pitrou, eric.smith, eric.snow
2016-06-19 12:01:09serhiy.storchakasetmessageid: <1466337669.2.0.193833385692.issue22557@psf.upfronthosting.co.za>
2016-06-19 12:01:09serhiy.storchakalinkissue22557 messages
2016-06-19 12:01:08serhiy.storchakacreate