Skip to content

Commit 37fc334

Browse files
committed
Misc doc, pyo3
1 parent 8cc10c8 commit 37fc334

7 files changed

Lines changed: 32 additions & 63 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ encoding_rs = { version = "0.8", default_features = false, features = ["simd-acc
5353
itoa = { version = "0.4", default_features = false }
5454
lazy_static = { version = "1.4.0", default_features = false }
5555
parking_lot = {version = "0.9", features = ["nightly"]}
56-
pyo3 = { git = "https://github.com/PyO3/pyo3.git", rev = "ce4b3a56a581c402bb67397590b66f1a0c12ba45", default_features = false, features = ["extension-module"]}
56+
pyo3 = { git = "https://github.com/PyO3/pyo3.git", rev = "75516d87eb83d10ed298581ef15b4e54c393df2c", default_features = false, features = ["extension-module"]}
5757
rand = { version = "0.7", default_features = false, features = ["getrandom", "std"] }
5858
serde = { version = "1", default_features = false }
5959
serde_json = { git = "https://github.com/ijl/json.git", rev = "0e82f6055fc062888026229d3208466f2c99182a", default_features = false, features = ["perfect_float"] }

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ pass `bytes`. This has lower memory usage and lower latency.
131131

132132
orjson maintains a cache of map keys for the duration of the process. This
133133
causes a net reduction in memory usage by avoiding duplicate strings. The
134-
keys must be at most 64 bytes to be cached and 512 entries are stored.
134+
keys must be at most 64 chars to be cached and 512 entries are stored.
135135

136136
It raises `JSONDecodeError` if given an invalid type or invalid
137137
JSON. This includes if the input contains `NaN`, `Infinity`, or `-Infinity`,
138138
which the standard library allows, but is not valid JSON.
139139

140-
`JSONDecodeError` is a subclass of `ValueError`. This is for
141-
compatibility with the standard library.
140+
`JSONDecodeError` is a subclass of `json.JSONDecodeError` and `ValueError`.
141+
This is for compatibility with the standard library.
142142

143143
### datetime
144144

@@ -268,10 +268,10 @@ ValueError: Parse error at offset 1: The surrogate pair in string is invalid.
268268

269269
## Testing
270270

271-
The library has comprehensive tests. There are unit tests against the
272-
roundtrip, jsonchecker, and fixtures files of the
271+
The library has comprehensive tests. There are tests against fixtures in the
272+
[JSONTestSuite](https://github.com/nst/JSONTestSuite) and
273273
[nativejson-benchmark](https://github.com/miloyip/nativejson-benchmark)
274-
repository. It is tested to not crash against the
274+
repositories. It is tested to not crash against the
275275
[Big List of Naughty Strings](https://github.com/minimaxir/big-list-of-naughty-strings).
276276
It is tested to not leak memory. It is tested to be correct against
277277
input from the PyJFuzz JSON fuzzer. It is tested to not crash
@@ -408,8 +408,8 @@ calling `loads()` on the fixture.
408408
| orjson | 12.8 | 2.7 |
409409
| ujson | 12.8 | 4.6 |
410410
| rapidjson | 14.3 | 6.4 |
411-
| json | 12.3 | 2.5 |
412411
| simplejson | 13 | 2.8 |
412+
| json | 12.3 | 2.5 |
413413

414414
#### github.json
415415

@@ -418,8 +418,8 @@ calling `loads()` on the fixture.
418418
| orjson | 12.3 | 0.3 |
419419
| ujson | 12.4 | 0.5 |
420420
| rapidjson | 13.8 | 0.5 |
421-
| json | 11.7 | 0.3 |
422421
| simplejson | 12.4 | 0.3 |
422+
| json | 11.7 | 0.3 |
423423

424424
#### citm_catalog.json
425425

@@ -428,18 +428,18 @@ calling `loads()` on the fixture.
428428
| orjson | 13.9 | 8.3 |
429429
| ujson | 13.8 | 12 |
430430
| rapidjson | 15.5 | 20.3 |
431-
| json | 13.4 | 20.2 |
432431
| simplejson | 14.1 | 21.8 |
432+
| json | 13.4 | 20.2 |
433433

434434
#### canada.json
435435

436436
| Library | import, read() RSS (MiB) | loads() increase in RSS (MiB) |
437437
|------------|----------------------------|---------------------------------|
438438
| orjson | 16.5 | 17.5 |
439-
| ujson | 16.4 | 19.4 |
439+
| ujson | | |
440440
| rapidjson | 17.8 | 19.8 |
441-
| json | 16.1 | 21.3 |
442441
| simplejson | 16.5 | 21.3 |
442+
| json | 16.1 | 21.3 |
443443

444444
### Reproducing
445445

bench/mem_usage

Lines changed: 0 additions & 37 deletions
This file was deleted.

bench/run_mem

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ mem_after = proc.memory_info().rss
3939

4040
mem_diff = mem_after - mem_before
4141

42-
print(f"{mem_before},{mem_diff}")
42+
from json import loads as json_loads
43+
correct = 1 if (json_loads(fixture) == json_loads(dumps(loads(fixture)))) else 0
44+
45+
print(f"{mem_before},{mem_diff},{correct}")

pybench

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/sh -e
22

3-
rm -rf .benchmarks
43
pytest \
54
--verbose \
65
--benchmark-min-time=1 \

pymem

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buf = io.StringIO()
1010

1111
headers = ("Library", "import, read() RSS (MiB)", "loads() increase in RSS (MiB)")
1212

13-
LIBRARIES = ("orjson", "ujson", "rapidjson", "json", "simplejson")
13+
LIBRARIES = ("orjson", "ujson", "rapidjson", "simplejson", "json")
1414

1515
FIXTURES = ("canada.json", "citm_catalog.json", "github.json", "twitter.json")
1616

@@ -21,10 +21,14 @@ for fixture in sorted(FIXTURES, reverse=True):
2121
proc = subprocess.Popen(
2222
("bench/run_mem", f"data/{fixture}.xz", lib_name), stdout=subprocess.PIPE
2323
)
24-
output = proc.stdout.readline().decode("utf-8").split(",")
24+
output = proc.stdout.readline().decode("utf-8").strip().split(",")
2525
mem_base = int(output[0]) / 1024 / 1024
2626
mem_diff = int(output[1]) / 1024 / 1024
27-
table.append((lib_name, f"{mem_base:,.1f}", f"{mem_diff:,.1f}"))
27+
correct = bool(int(output[2]))
28+
if correct:
29+
table.append((lib_name, f"{mem_base:,.1f}", f"{mem_diff:,.1f}"))
30+
else:
31+
table.append((lib_name, "", ""))
2832
buf.write(tabulate(table, headers, tablefmt="grid") + "\n")
2933

3034
print(

0 commit comments

Comments
 (0)