Brett Cannon <br...@python.org> added the comment:

OK, so a cursory look at importlib suggests that the possible costs of those 
stat calls (by looking at what has to examine the filesystem) are:

* os.listdir() for caching
* os.path.isdir() for directories if they are a package
* os.path.isfile() for __init__.py
* os.path.isfile() for a module (and all the possible extensions)
* os.stat() for details of bytecode
* reading any bytecode
* reading the source
* writing the bytecode

So looking at that initial block of stat calls, I am willing to bet that Lib is 
getting the stat call by the os.path.isdir() check in the finder, the 2 
Lib/_sysconfigdata.py checks are from the finder checking the file exists and 
then stat'ing in the loader for bytecode verification, and then finally the 
opening of the bytecode to read it and discover it's usable.

As for the multiple stat calls on directories, that's validating the cache 
isn't out-of-date which I don't see how that can be avoided short of hitting 
the system clock to see if some amount of time has passed.

As for the multiple stat calls between the finder and the loader, I don't see 
any way to cut that down without coming up with a find + load API which makes 
the call immediately or some way to pass in stat details, else you have race 
conditions on the status of the file before you check if the bytecode is stale. 
If the stat calls on the directories for cache validation is too frequent, then 
issue #14067 is probably your best bet.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14604>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to