Proposal: Inline Import
Shane Hathaway
shane at hathawaymix.org
Sat Dec 10 03:16:00 EST 2005
Kent Johnson wrote:
> Shane Hathaway wrote:
>>I'm talking about using imports *everywhere*. The penalty would be
>>appreciable.
>
>
> Have you tried it?
>
> D:\Projects\CB>python -m timeit -s "import re" "import re"
> 1000000 loops, best of 3: 1.36 usec per loop
>
> You need a lot of imports before 1 usec becomes "appreciable".
Let me fully elaborate the heresy I'm suggesting: I am talking about
inline imports on every other line of code. The obvious implementation
would drop performance by a double digit percentage.
> And your
> proposal is doing the import anyway, just under the hood. How will you
> avoid the same penalty?
The more complex implementation, which I suggested in the first message,
is to maintain a per-module dictionary of imported objects (distinct
from the global namespace.) This would make inline imports have almost
exactly the same runtime cost as a global namespace lookup.
But never mind, this proposal is a distraction from the real issue. See
the next thread I'm starting.
Shane
More information about the Python-list
mailing list