A smarter(?) package importer.
Rainer Deyke
root at rainerdeyke.com
Wed Nov 7 09:09:10 EST 2001
"Prabhu Ramachandran" <prabhu at aero.iitm.ernet.in> wrote in message
news:mailman.1005121809.21819.python-list at python.org...
> 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.
Dictionary access is fast. The time needed for dictionary access does not
deepend on the size of the dictionary except in degenerate cases. Opening a
file is a slow operation, even if it results in failure.
>
> pkg/
> sub/
> subsub/
> foo.py
>
> foo.py:
> import string
>
> This would insert all of the following into sys.modules:
> subsub.string, sub.string, pkg.string, string
Technically, it would add "pkg.sub.subsub.string", "pkg.sub.string",
"pkg.string", and "string".
> so if each and every package did this we'd have way too many 'string's
> that point to None. This means that len(sys.modules) increases quite
> significantly. Or can it be proved that caching is better than not
> caching at all?
It can, and probably has been, but I'm not going to. Test it yourself if
you're really interested; I'm going to trust the Python implementation team
on this one.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list