[Python-Dev] 2.5a2 try/except slow-down: Convert to type?

Sean Reifschneider jafo-python-dev at tummy.com
Wed May 24 12:24:41 CEST 2006


We're working at the sprint on tracking this down.  I want to provide some
history first and then what we're looking for feedback on.

Steve Holden found this on Sunday, the pybench try/except test shows a ~60%
slowdown from 2.4.3 to 2.5a2.  The original test is, roughly:

   for i in range(N):
      try: raise ValueError, 'something'
      except: pass

But changing it to the following shows 0% slowdown from 2.4.3 to 2.5a2:

   e = ValueError('something')
   for i in range(N):
      try: raise e
      except: pass

The change is that from 2.4.3 to 2.5a2 includes Brett Cannon's patch to make
exceptions all new-style objects.

Brett provided the following direction:

   >Right, I meant change how it (BaseException) is written.  Right now
   >it uses PyMethodDef for magic methods and just uses PyType_New()
   >as a constructor.  I was wondering if, for some reason, it would be
   >faster if you used a PyType_Type definition for BaseException and
   >used the proper C struct to associate the methods with the class.

Richard Jones has done some investigation, and we're looking at fixing
it from the current implementation.  This is basically a direct
implementation of the old-style exception, but inheriting from object.
Converting it to a type in C should reduce the cost dramatically.

We're looking for feedback on where this may cause problems or break
things.  Thoughts?

Thanks,
Sean
-- 
 Thieves broke into Scotland Yard yesterday and stole all the toilets.
 Detectives say they have nothing to go on.
Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995: Ask me about High Availability



More information about the Python-Dev mailing list