[IronPython] [python] Import Performance

Davy Mitchell daftspaniel at gmail.com
Thu Dec 27 18:44:22 CET 2007


Hi All,

Okay had a go at narrowing down the issue - appears to be the 'import
compiler' line taking around 2 seconds. The importing seems pretty
fast - possibly the exceptions in IronPython being generated causing
the slowdown.

Here's the test code I used:
import sys
import datetime
print datetime.datetime.now()
try:
    import antigravity
except ImportError:
    pass
print datetime.datetime.now()
try:
    import compiler
except ImportError:
    print " Error \n", sys.exc_info()[0]
    for line in sys.exc_info():
        print line
print datetime.datetime.now()

CPython:
2007-12-27 17:35:57.279000
2007-12-27 17:35:57.284000
2007-12-27 17:35:57.316000

IronPython:
2007-12-27 17:37:59.502000
2007-12-27 17:37:59.528000
 Error
exceptions.ImportError
exceptions.ImportError
No module named parser
<traceback object at 0x000000000000002B>
2007-12-27 17:38:01.664000

Both cope with unknown modules fast but it appears the exception
condition causes the slowdown.

This is a common way for optional or preferred modules to be imported
so I would say this is probably an issue though not having worked on
anything large enough in IronPython to draw firm conclusions!! CPython
seems to be about 10 times faster importing modules from the various
benchmarks I have run.

Easy workaround for me is to remove the import from configobj - hurrah :-)

Cheers,
Davy

On Dec 26, 2007 9:56 PM, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> Davy Mitchell wrote:
> > I was curious as to why one of my apps was taking so long to start up.
> > Sure it loaded up some RSS feeds but it shouldn't take *that* long.
> > Anyway turns out to be 4-5 seconds importing configobj
> >
> > import datetime
> > print datetime.datetime.now()
> > from configobj import ConfigObj
> > print datetime.datetime.now()
> >
> > Repeated with consistent results in seconds:
> > IPY2.0      4.0 (A6 and A7)
> > IPY1.1      1.9
> > Cpython    0.1
> >
> > Not a huge issue for me but for large apps, this could be quite
> > significant for startup times.
> >
>
> Can you benchmark which bits of the import take how much time?
>
> Michael
>
> > Cheers,
> > Davy
> >
> >
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>



-- 
Davy Mitchell
Blog - http://www.latedecember.co.uk/sites/personal/davy/
Twitter - http://twitter.com/daftspaniel
Skype - daftspaniel                                          needgod.com



More information about the Ironpython-users mailing list