This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jonash
Recipients jonash, theller
Date 2011-02-20.16:03:57
SpamBayes Score 1.1044893e-07
Marked as misclassified No
Message-id <1298217839.35.0.775539629492.issue11258@psf.upfronthosting.co.za>
In-reply-to
Content
(This applies to all versions of Python I investigated, although the attached patch is for Python 2.7)

I wondered why `import uuid` took so long, so I did some profiling.

It turns out that `find_library` wastes at lot of time because of this crazy regular expression in `_findSoname_ldconfig`.

A quick look at the ldconfig source (namely, the print_cache routine which is invoked when you call `ldconfig -p`, http://sourceware.org/git/?p=glibc.git;a=blob;f=elf/cache.c#l127) confirmed my suspicion that the ldconfig's output could easily be parsed without such a regex monster.

I attached two patches that fix this problem. Choose one! ;-)

The ctypes tests pass with my fixes, and here comes some benchmarking:

$ cat benchmark_ctypes.py 
from ctypes.util import find_library
for i in xrange(10):
  for lib in ['mm', 'c', 'bz2', 'uuid']:
    find_library(lib)

# Current implementation
$ time python benchmark_ctypes.py 
real    0m11.813s
...
$ time python -c 'import uuid'
real    0m0.625s
...

# With my patch applied
$ cp /tmp/ctypesutil.py ctypes/util.py
$ time python benchmark_ctypes.py 
real    0m1.785s
...
$ time python -c 'import uuid'
real    0m0.182s
...
History
Date User Action Args
2011-02-20 16:04:00jonashsetrecipients: + jonash, theller
2011-02-20 16:03:59jonashsetmessageid: <1298217839.35.0.775539629492.issue11258@psf.upfronthosting.co.za>
2011-02-20 16:03:58jonashlinkissue11258 messages
2011-02-20 16:03:58jonashcreate