[Python-Dev] [Python-checkins] cpython: Issue #18810: Be optimistic with stat calls when seeing if a directory (original) (raw)
Brett Cannon brett at python.org
Sat Oct 19 15:54:07 CEST 2013
- Previous message: [Python-Dev] [Python-checkins] cpython: Issue #18810: Be optimistic with stat calls when seeing if a directory
- Next message: [Python-Dev] [Python-checkins] cpython: Issue #18810: Be optimistic with stat calls when seeing if a directory
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Oct 18, 2013 at 9:06 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
On 19 Oct 2013 03:24, "brett.cannon" <python-checkins at python.org> wrote: > > http://hg.python.org/cpython/rev/11f2f4af1979 > changeset: 86444:11f2f4af1979 > user: Brett Cannon <brett at python.org> > date: Fri Oct 18 13:24:13 2013 -0400 > summary: > Issue #18810: Be optimistic with stat calls when seeing if a directory > exists when checking for a package. > > Before there was an isdir check and then various isfile checks for > possible init files when looking for a package. > This change drops the isdir check by leaning > on the assumption that a directory will not contain something named > after the module being imported which is not a directory. If the module > is a package then it saves a stat call. If there is nothing in the > directory with the potential package name it also saves a stat call. > Only if there is something in the directory named the same thing as > the potential package will the number of stat calls increase > (due to more wasteful init checks). I don't follow this logic. There's now not even an existence check for the base name, so it reads to me like we will look for all the possible init file extensions even if there's no directory with an appropriate name. What am I missing?
if cache_module in cache:
, the line above the _path_join() call and the
guard that blocks the entire package search.
-Brett
Cheers, Nick.
> > Semantically there is no change as the isdir check moved > down so that namespace packages continue to have no chance of > accidentally collecting non-existent directories. > > files: > Lib/importlib/bootstrap.py | 19 +- > Python/importlib.h | 1537 +++++++++++----------- > 2 files changed, 777 insertions(+), 779 deletions(-) > > > diff --git a/Lib/importlib/bootstrap.py b/Lib/importlib/bootstrap.py > --- a/Lib/importlib/bootstrap.py > +++ b/Lib/importlib/bootstrap.py > @@ -1406,16 +1406,15 @@ > # Check if the module is the name of a directory (and thus a package). > if cachemodule in cache: > basepath = pathjoin(self.path, tailmodule) > - if pathisdir(basepath): > - for suffix, loader in self.loaders: > - initfilename = 'init' + suffix > - fullpath = pathjoin(basepath, initfilename) > - if pathisfile(fullpath): > - return (loader(fullname, fullpath), [basepath]) > - else: > - # A namespace package, return the path if we don't also > - # find a module in the next section. > - isnamespace = True > + for suffix, loader in self.loaders: > + initfilename = 'init' + suffix > + fullpath = pathjoin(basepath, initfilename) > + if pathisfile(fullpath): > + return (loader(fullname, fullpath), [basepath]) > + else: > + # If a namespace package, return the path if we don't > + # find a module in the next section. > + isnamespace = pathisdir(basepath) > # Check for a file w/ a proper suffix exists. > for suffix, loader in self.loaders: > fullpath = pathjoin(self.path, tailmodule + suffix) > diff --git a/Python/importlib.h b/Python/importlib.h > --- a/Python/importlib.h > +++ b/Python/importlib.h > [stripped] > > -- > Repository URL: http://hg.python.org/cpython > _> ________________________ > Python-checkins mailing list > Python-checkins at python.org > https://mail.python.org/mailman/listinfo/python-checkins >
Python-checkins mailing list Python-checkins at python.org https://mail.python.org/mailman/listinfo/python-checkins -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20131019/c147283d/attachment-0001.html>
- Previous message: [Python-Dev] [Python-checkins] cpython: Issue #18810: Be optimistic with stat calls when seeing if a directory
- Next message: [Python-Dev] [Python-checkins] cpython: Issue #18810: Be optimistic with stat calls when seeing if a directory
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]