[Python-Dev] inspect.py very slow under 2.5

Nick Coghlan ncoghlan at gmail.com
Wed Sep 6 12:54:45 CEST 2006


Ralf Schmitt wrote:
> The problem seems to originate from the module=getmodule(object) in 
> findsource. If I outcomment that code (or rather do a module=None),
> things seem to be back as normal. (linecache.getlines has been called 
> with a None module in python 2.4's inspect.py).

It looks like the problem is the call to getabspath() in getmodule(). This 
happens every time, even if the file name is already in the modulesbyfile 
cache. This calls os.path.abspath() and os.path.normpath() every time that 
inspect.findsource() is called.

That can be fixed by having findsource() pass the filename argument to 
getmodule(), and adding a check of the modulesbyfile cache *before* the call 
to getabspath().

Can you try this patch and see if you get 2.4 level performance back on 
Fernando's test?:

http://www.python.org/sf/1553314

(Assigned to Neal in the hopes of making 2.5rc2)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list