Closed ara4n closed 6 years ago
Empirically, no we haven't broken performance, since matrix.org is now using simplejson without a catastrophic decrease in performance.
I have spent some time profiling ujson
, simplejson
and json
; the results look like this:
(In the above, simplejson
uses simplejson.dumps
; simplejson_static
creates a static JSONEncoder
and JSONDecoder
and uses encode
and decode
).
Conclusions are:
simplejson
outperforms ujson
for large objects and is comparable for small objects. Stock json
is much slower than either.ujson
, and 1.5x as slow even as stock json
.Despite that, I think we want to use simplejson
anyway. The reasons for this are:
ujson
does not appear to be well-maintained. The bug we found was indeed fixed over a year ago, but that has yet to be released (and I am really not keen to depend on a git version of it, since we'd have to ship our own binaries for debian etc)sort_keys=True
, as used in canonicaljson
), json
is way slower than simplejson
.simplejson
's superior load
performance wins over json
's superior dump
performance. We may also be able to push a few optimisations upstream (see https://github.com/simplejson/simplejson/pull/212, for example).As part of this work, I've also discovered that canonicaljson
is slow (4x slower than simplejson
for canonicaljson 1.0.0
, though this is reduced to 1.5x in canonicaljson 1.1.0
).
Keeping this open for now, until we merge canonicaljson 1.1.0
Canonicaljson 1.1.2 is now released, and matrix.org is using it.
And whet we'd be better off pinning against a non-broken version of ujson (as apparently the upstream git is fixed).
See https://github.com/matrix-org/synapse/pull/3008