Skip to content

Use json instead of simplejson #146

@ijl

Description

@ijl

itsdangerous and by extension flask, starlette, and others use simplejson if it's installed due to:

try:
    import simplejson as json
except ImportError:
    import json

Is there still a reason to use simplejson? I don't know of a feature or compatibility reason.

The reason I have seen mentioned is better performance. That is not the case with at least python3.6+ and a modern distribution (that probably compiled python with PGO and LTO) with simplejson compiled. See these benchmarks.

If simplejson is installed in a container without a compiler, it falls back to running in pure Python. This is a footgun:

In [1]: import json, simplejson

In [2]: data = list(range(0, 100000))

In [3]: %timeit json.dumps(data)
17.4 ms ± 1.14 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [4]: %timeit simplejson.dumps(data)
89.4 ms ± 7.21 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

It seems preferable to just use json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions