[Python-Dev] PEP 273 - Import from Zip Archives

James C. Ahlstrom jim@interet.com
Thu, 28 Feb 2002 12:16:05 -0500

Gordon McMillan wrote:

> On 28 Feb 2002 at 9:44, James C. Ahlstrom wrote:
>>The other objection raised at the time was the
>>possible slow down of imports. 
> imputil was 30 to 40% slower than C import. iu
> is about 10 to 15% slower under normal usage, but
> can be faster if you use archives and arrange sys.path
> intelligently.

I think I can add iu.py as the standard Python importer
to my import.c patches.  That is, if iu.py can be imported
(using C), then it takes over imports.  Note that the C code
changes to import.c are still required.  Also note that iu.py
may be in a zip file, and so the import.c changes are still

>>My code uses os.listdir to cache directory
>>contents, but defers its use until the os module can
>>be imported using the C import code. 
> A win over some threshold of number of hits on
> that directory; a loss under that threshold.

Exactly correct.  It is tradeoff between the OS caching
directory hits from fopen() versus using a Python cache
and os.listdir().  Dramatic gains are obtained when importing
from network file systems, an important case.