[Python-Dev] possibility of shaving a stat call from imports (original) (raw)
Eric Snow ericsnowcurrently at gmail.com
Sat Oct 19 00:52:11 CEST 2013
- Previous message: [Python-Dev] possibility of shaving a stat call from imports
- Next message: [Python-Dev] possibility of shaving a stat call from imports
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Oct 18, 2013 at 2:59 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
Is it one stat() call per successful import? Or one stat() call per sys.path entry?
It's one per finder (i.e. path entry) where a matching name is in the directory (per the finder's cache). So it's a pretty uncommon case with not much overhead when the name is not in the cache.
The same thing happens earlier with directories, checking to see if the name was in the cache and then checking if it is a directory (_path_isdir). Again, uncommon and otherwise not all that impactful on performance.
In the directory case removing the directory check might be inadvisable since it it would result in a _path_isfile call for each registered suffix before moving on (plus it would be incorrectly considered a portion of a potential namespace package). Of course, this is what happens already with directories that have no init. file in them, which is also an unlikely case that doesn't make much of a difference on performance normally.
In the file case I agree that it's much more unlikely that there will be a directory in just the right place with a .py (etc.) suffix in the name.
In either case I don't think it saves us much performance-wise, but it may be nice to make that code a simpler if it won't realistically cause anyone headaches. I'm fine with just leaving it as-is.
(Also, FTR Brett's email relates to http://bugs.python.org/issue18810.)
-eric
p.s. I brought up the same point about dir/file checks in http://bugs.python.org/issue19216.
- Previous message: [Python-Dev] possibility of shaving a stat call from imports
- Next message: [Python-Dev] possibility of shaving a stat call from imports
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]