ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> import-sig
import-sig
[Import-sig] Re: Proposal for a modified import mechanism.
by Prabhu Ramachandran other posts by this author
Nov 11 2001 8:03AM messages near this date
[Import-sig] Re: Proposal for a modified import mechanism. | Re: [Import-sig] Re: Proposal for a modified import mechanism.
> >>>> "ej" == ej  <eric> writes:

[snip]
    ej>  The current runtime overhead isn't so bad.  Prabhu sent me a
    ej>  few numbers on the SciPy import (which contains maybe 10-15
    ej>  nested packages).  I attached them below -- the overhead is
    ej>  less than 10%.  It should be negligible for standard modules
    ej>  as only packages are really affected (right Prabhu?).

It depends on how you do it.  If you have a sub-package that tries to
import a standard module it will go through all the parent packages
searching for the module and when it doesn't find one it will check in
sys.path.  There are a few things to note:

  (1) For a module in a package, the first import will be naturally
  the slowest.

  (2) Subsequent imports will be faster since failures are cached and
  the package is already imported.

  (3) If the module in question is not inside a package there will be
  no slowdown whatsoever since there is no parent package at all.
  I've timed this with vtk and it seems to be correct.

> >> import my_import, time # NOTE: I am not inside any package.
> >> s = time.time (); import vtkpython; print time.time()-s
1.06130003929

> >> import time
> >> s = time.time (); import vtkpython; print time.time()-s
1.06413698196

Its slower with standard import you may say - but that might just be
my kernel's scheduling affecting things.  I think its fair to conclude
that there is no slowdown if you are not inside a package and based on
my earlier timings, that recursive searching thru package parents is
not too expensive either.

There is one issue.  lets say we have two sub-packages that have
modules of the same name.  Then if we explicitly want the other
sub-packages module to be imported there is currently no way of doing
it.  In such a case maybe adding a __parent__ or using (__ as ni did)
might be a good idea too.

prabhu

_______________________________________________
Import-sig mailing list
Import-sig@[...].org
http://mail.python.org/mailman/listinfo/import-sig
Thread:
eric
Prabhu Ramachandran
Prabhu Ramachandran
Prabhu Ramachandran
Gordon McMillan
James C. Ahlstrom
Barry A. Warsaw
Gordon McMillan
Toby Dickenson
Steve Holden
Barry A. Warsaw
Prabhu Ramachandran
Barry A. Warsaw
Fredrik Lundh
Barry A. Warsaw
Prabhu Ramachandran
Prabhu Ramachandran
Prabhu Ramachandran
Barry A. Warsaw
Michel Pelletier
Prabhu Ramachandran
Michel Pelletier
James C. Ahlstrom
Prabhu Ramachandran
Prabhu Ramachandran
Prabhu Ramachandran
eric
Prabhu Ramachandran
eric
Gordon McMillan
Toby Dickenson
M.-A. Lemburg
Barry A. Warsaw
Fredrik Lundh
Prabhu Ramachandran
Barry A. Warsaw
Michel Pelletier
Prabhu Ramachandran
James C. Ahlstrom
Gordon McMillan
Barry A. Warsaw
Prabhu Ramachandran
Prabhu Ramachandran
Barry A. Warsaw
Prabhu Ramachandran
James C. Ahlstrom
Prabhu Ramachandran
Jeremy Hylton
Prabhu Ramachandran
Jeremy Hylton
Prabhu Ramachandran
Jeremy Hylton
Prabhu Ramachandran
Prabhu Ramachandran
Greg Ward
Just van Rossum
Thomas Heller
Just van Rossum
Jeremy Hylton
Gordon McMillan
Gordon McMillan
Gordon McMillan
Prabhu Ramachandran
Jeremy Hylton
Prabhu Ramachandran
Prabhu Ramachandran
Jeremy Hylton
Prabhu Ramachandran
Jeremy Hylton
Jeremy Hylton
eric
Prabhu Ramachandran
Gordon McMillan
Prabhu Ramachandran
Gordon McMillan
Prabhu Ramachandran

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved