A smarter(?) package importer.

Gordon McMillan gmcm at hypernet.com
Wed Nov 7 14:44:28 CET 2001

Prabhu Ramachandran wrote:

[import caching failures]

> Does the performance boost occur mainly because each subsequent
> failure would mean that sys.modules would have to scan through all of
> its keys and then fail?  Hmmm, but if you kept caching failure, you'd
> increase the number of keys.  If the package nesting is substantial
> for every global module this would insert several new item into
> sys.modules.

But sys.modules is a dictionary. It's hashed, not scanned.
If you *don't* cache failure, you get 3 (4 on Windows) attempted 
opens per directory that you could have avoided.

- Gordon

More information about the Python-list mailing list