Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use orjson for JSON serialization #4801

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

judahrand
Copy link
Contributor

What does this PR address?

orjson seems to perform ~10x better than the stdlib json for roundtrip serialization:

In [1]: import json

In [2]: import orjson

In [3]: import random

In [4]: py_list = [random.random() for x in range(1000)]

In [5]: %timeit orjson.loads(orjson.dumps(py_list))
40.9 μs ± 178 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

In [6]: %timeit json.loads(json.dumps(py_list))
522 μs ± 8.43 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

In [7]: %timeit orjson.loads(orjson.dumps('string'))
93.4 ns ± 0.882 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

In [8]: %timeit json.loads(json.dumps('string'))
824 ns ± 3.81 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

Fixes #(issue)

Before submitting:

@judahrand judahrand requested a review from a team as a code owner June 13, 2024 13:57
@judahrand judahrand requested review from frostming and removed request for a team June 13, 2024 13:57
@frostming
Copy link
Contributor

This should better be an optional dependency and expose a uniform API from a wrapper module.

@judahrand
Copy link
Contributor Author

This should better be an optional dependency and expose a uniform API from a wrapper module.

Why do you think that is necessary? pydantic is already a dependency which (if wheels are not available) requires a Rust toolchain. It doesn't feel like adding orjson is much of a stretch especially since it builds wheels for basically every platform. In addition it is only ~500kB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants