Add an 'extra' optional, orjson to experiment with rust speedups#64
Add an 'extra' optional, orjson to experiment with rust speedups#64realtyem wants to merge 10 commits intomatrix-org:mainfrom
orjson to experiment with rust speedups#64Conversation
…f 2, so adjust a test
…ew orjson extra option
…immutabledict and add this as a test Side effect: drop in support for anything Synapse registers
anoadragon453
left a comment
There was a problem hiding this comment.
Thanks for this! To move this along, could you:
- Separate out dropping Python 3.7 support (it's been EOL for a while, so we should drop it across the repo) into a new PR?
- Remove the base vs. orjson tox config now (including coverage changes) as we have seen an improvement in the test case runtimes 🎉
| # orjson's pretty print style is a flag option and is hardcoded to "2", | ||
| # so this will be slightly different. |
There was a problem hiding this comment.
It might be worth proposing an OPT_INDENT_4 to upstream?
It's not ideal that we'll be changing the output of encode_pretty_printed_json (in case it breaks downstream test cases), but it's possible with a version bump/note in the changelog.
| data_with_inf = {"a": 1, "b": float("inf")} | ||
| data_with_neg_inf = {"a": 1, "b": -float("inf")} | ||
| data_with_nan = {"a": 1, "b": float("nan")} | ||
| list_with_inf = {"a": [1, float("inf")]} | ||
| list_with_neg_inf = {"a": [1, -float("inf")]} | ||
| list_with_nan = {"a": [1, float("nan")]} | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_canonical_json(data_with_inf) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_pretty_printed_json(data_with_inf) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_canonical_json(data_with_neg_inf) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_pretty_printed_json(data_with_neg_inf) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_canonical_json(data_with_nan) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_pretty_printed_json(data_with_nan) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_canonical_json(list_with_inf) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_pretty_printed_json(list_with_inf) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_canonical_json(list_with_neg_inf) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_pretty_printed_json(list_with_neg_inf) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_canonical_json(list_with_nan) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| encode_pretty_printed_json(list_with_nan) |
There was a problem hiding this comment.
This would be more readable if the test cases were looped over, i.e.:
test_cases = {
"data_with_inf": {"a": 1, "b": float("inf")},
...
}
for name, test_case in test_cases.items():
with self.assertRaises(ValueError, f"Passing test case '{name}' to encode_canonical_json failed to raise a ValueError"):
encode_canonical_json(test_case)
with self.assertRaises(ValueError, f"Passing test case '{name}' to encode_pretty_printed_json failed to raise a ValueError"):
encode_pretty_printed_json(test_case)There was a problem hiding this comment.
Oh, I like that. Yes, will do 🫡
For clarity... And for the second bit, just have only |
The
orjsonproject reports a(sometimes several) order of magnitude speed up in serializing/deserializing JSON. Let's try it out