[Python-Dev] method dispatch vs. switching (pickle faster in 2.2 ?)
Guido van Rossum
guido@python.org
Thu, 01 Nov 2001 07:56:02 -0500
> Guido van Rossum wrote:
> >
> > > While hacking on an XML pickler, I found that pickle.py got nearly
> > > twice as fast in 2.2 comparing to 2.1 and 2.0.
> >
> > What benchmark?
>
> I was looking at the roundtrip speed of pickling a list of integers.
>
> > > The code in pickle.py doesn't seem to have changed much. Anybody
> > > know where that speedup came from ? Can somebody on another
> > > (non-Linux) system please verify this.
> >
> > I believe DOM nodes are now new-style classes, for better or for worse
> > (it might create problems when combining with classic mixins). Could
> > that explain it?
>
> No. I'm writing my own little beast here which does not use DOM,
> expat or sgmlop.
>
> The results of the approach which tries to avoid Python
> function calls are interesting. I moved from the usual
> switch strategy of dispatching to instance methods to a
> large for-loop with lots of "if x is y: ...". While I suspected
> the latter to be faster on average, I found that this is
> not the case. I still have to investigate where the performance
> goes, but the result kind of surprised me.
Sorry, it's too early for me to understand what the two alternatives
are. :-)
--Guido van Rossum (home page: http://www.python.org/~guido/)