[Python-Dev] Status of json (simplejson) in cpython

Vinay Sajip vinay_sajip at yahoo.co.uk
Sun Apr 17 12:46:41 CEST 2011


Stefan Behnel <stefan_ml <at> behnel.de> writes:

> Well, if that is not possible, then the CPython devs will have a hard time 
> maintaining the json accelerator module in the long run. I quickly skipped 
> through the github version in simplejson, and it truly is some complicated 
> piece of code. Not in the sense that the code is ununderstandable, it's 
> actually fairly straight forward string processing code, but it's so 
> extremely optimised and tailored and has so much code duplicated for the 
> bytes and unicode types (apparently following the copy+paste+adapt pattern) 
> that it will be pretty hard to adapt to future changes of CPython, 
> especially the upcoming PEP 393 implementation. Maintaining this is clearly 
> no fun.

Do we even need this complexity in Python 3.x? The speedup code for 2.x is
taking different, parallel paths for str and unicode types, either of which
might be legitimately passed into JSON APIs in 2.x code. However, in Python 3.x,
ISTM we should not be passing in bytes to JSON APIs. So there'd be no equivalent
parallel paths for bytes for 3.x speedup code to worry about.

Anyway, some simple numbers posted by me elsewhere on this thread show
simplejson to be only around 2% faster. Talk of a 5x speedup appears to be
comparing non-speeded up vs. speeded up code, in which case the comparison isn't
valid.

Of course, people might find other workloads which show bigger disparity in
performance, or might find something in my 3.x port of simplejson which
invalidates my finding of a 2% difference.

Regards,

Vinay Sajip



More information about the Python-Dev mailing list