[Twisted-Python] Re: Disabling PB (de)serialization

Brian Warner warner at lothar.com
Tue Sep 6 15:38:26 EDT 2005

>> Well, you can uncomment the cBanana hook in the PB code, and they will
>> be much faster. :-)
> Oooh, seriously? Where do I do that?

Hm, I thought cBanana was the default? It might depend upon how you
build/install Twisted.. there are platforms on which the optional C
extensions are just skipped.

Oh, there it is.. twisted/spread/banana.py, towards the end, just grep for
'import cBanana'. Exarkun commented that out last year. Eh, give it a try,
see if it helps. I'd be a little bit worried about segfaulting, or exposing
such a port to a hostile party. But I honestly haven't looked at that code
for two years.

cBanana implements the lowest layer of serialization/deserialization in C, so
it will be a little bit faster. If your data consists of a lot of strings and
ints, the speedup will probably be greater than if it consists of a lot of
interconnected lists and tuples. It would be neat to have some actual
benchmarks of the speedup, though.

newpb is designed to make it possible to write Slicers/Unslicers in C, and in
fact to allow the base-level Protocol to be implemented in C, but none of
these hypothetical accelerated serializers have actually been written yet.
This would allow C serialization of basic types (lists, tuples) while
retaining standard python serialization of user-defined complex types, as
opposed to the oldpb/cBanana approach that uses C for only the lowest level
(turning string/number tokens into bytes). In theory, it should be possible
to make newpb run faster than oldpb. It will take some good use-cases and
benchmarking before this actually happens, though.


More information about the Twisted-Python mailing list