fastsimdjson 0.10.3__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastsimdjson-0.10.3/src/fastsimdjson.egg-info → fastsimdjson-1.0.0}/PKG-INFO +344 -136
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/README.md +339 -134
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/pyproject.toml +4 -4
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/setup.py +1 -1
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/src/fastsimdjson.cpp +623 -120
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0/src/fastsimdjson.egg-info}/PKG-INFO +344 -136
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/src/fastsimdjson.egg-info/SOURCES.txt +3 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/src/fastsimdjson.egg-info/requires.txt +3 -0
- fastsimdjson-1.0.0/src/typed.h +1202 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/tests/test_arrow.py +74 -2
- fastsimdjson-1.0.0/tests/test_minify.py +165 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/tests/test_stream.py +140 -0
- fastsimdjson-1.0.0/tests/test_typed.py +635 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdjson_arrow.cpp +306 -6
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdjson_arrow.h +41 -9
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/MANIFEST.in +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/setup.cfg +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/src/fastsimdjson.egg-info/dependency_links.txt +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/src/fastsimdjson.egg-info/top_level.txt +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/tests/test_dumps.py +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/tests/test_files.py +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/tests/test_lazy.py +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/tests/test_loads.py +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/tests/test_msgpack.py +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdjson.cpp +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdjson.h +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdjson_arrow-LICENSE +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdjson_msgpack-LICENSE +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdjson_msgpack.cpp +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdjson_msgpack.h +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdutf.cpp +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdutf.h +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/simdutf_c.h +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/zmij-LICENSE +0 -0
- {fastsimdjson-0.10.3 → fastsimdjson-1.0.0}/vendor/zmij.h +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastsimdjson
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Fast JSON parsing for Python, built on simdjson
|
|
5
5
|
Author-email: Daniel Lemire <daniel@lemire.me>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -8,7 +8,7 @@ Project-URL: Homepage, https://github.com/simdjson/fastpysimdjson
|
|
|
8
8
|
Project-URL: Repository, https://github.com/simdjson/fastpysimdjson
|
|
9
9
|
Project-URL: Issues, https://github.com/simdjson/fastpysimdjson/issues
|
|
10
10
|
Keywords: json,simdjson,parser,simd,performance
|
|
11
|
-
Classifier: Development Status ::
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: Programming Language :: C++
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -25,10 +25,13 @@ Description-Content-Type: text/markdown
|
|
|
25
25
|
Provides-Extra: test
|
|
26
26
|
Requires-Dist: pytest; extra == "test"
|
|
27
27
|
Requires-Dist: msgpack; extra == "test"
|
|
28
|
+
Requires-Dist: typing_extensions; extra == "test"
|
|
28
29
|
Provides-Extra: bench
|
|
29
30
|
Requires-Dist: orjson; extra == "bench"
|
|
30
31
|
Requires-Dist: jiter; extra == "bench"
|
|
31
32
|
Requires-Dist: msgspec; extra == "bench"
|
|
33
|
+
Requires-Dist: pydantic; extra == "bench"
|
|
34
|
+
Requires-Dist: cattrs; extra == "bench"
|
|
32
35
|
Requires-Dist: pysimdjson; extra == "bench"
|
|
33
36
|
Requires-Dist: cysimdjson; extra == "bench"
|
|
34
37
|
Requires-Dist: pyarrow; extra == "bench"
|
|
@@ -42,7 +45,7 @@ Requires-Dist: ormsgpack; extra == "bench"
|
|
|
42
45
|
Fast JSON for Python, built on [simdjson](https://github.com/simdjson/simdjson),
|
|
43
46
|
the parser that reads JSON at gigabytes per second. fastsimdjson is a drop-in
|
|
44
47
|
replacement for the `json` module (`loads`, `load`, `dumps`, `dump`) that
|
|
45
|
-
gives the same results 3.5 to 4.
|
|
48
|
+
gives the same results 3.5 to 4.2 times faster, and it goes further: lazy
|
|
46
49
|
parsing, streams of documents on many threads, Apache Arrow tables and
|
|
47
50
|
MessagePack, in one package with no dependencies.
|
|
48
51
|
|
|
@@ -52,7 +55,7 @@ fastsimdjson is often two to four times faster than the alternatives:
|
|
|
52
55
|
|
|
53
56
|
<picture>
|
|
54
57
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_summary_dark.png">
|
|
55
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_summary.png" width="80%" alt="fastsimdjson against the competition, speed on one core relative to a fast alternative: Python objects to JSON str, 4.
|
|
58
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_summary.png" width="80%" alt="fastsimdjson against the competition, speed on one core relative to a fast alternative: Python objects to JSON str, 4.2 times json.dumps; MessagePack to JSON, 4.1 times ormsgpack with orjson; JSON to MessagePack, 3.6 times orjson with ormsgpack; NDJSON to Arrow, 3.6 times polars; Arrow to NDJSON, 2.4 times polars; a few fields of a document, 2.2 times msgspec; JSON to Python objects, 1.3 times orjson">
|
|
56
59
|
</picture>
|
|
57
60
|
|
|
58
61
|
Against the standard `json` module, `loads` is 3.5 times faster and `parse`
|
|
@@ -62,18 +65,23 @@ Against the standard `json` module, `loads` is 3.5 times faster and `parse`
|
|
|
62
65
|
* **Same results.** `loads` returns what `json.loads` returns, `dumps` the
|
|
63
66
|
same `str` as `json.dumps`, character for character, and `dumpb` the same
|
|
64
67
|
bytes as `orjson.dumps`. Switching changes the speed, not the output.
|
|
68
|
+
* **Typed.** `loads(data, type=T)` builds dataclasses, TypedDicts and
|
|
69
|
+
other typed values straight from the parser, with the types checked: 1.5
|
|
70
|
+
to 2.1 times as fast as msgspec, 3.9 to 5.1 times as fast as pydantic.
|
|
65
71
|
* **Only what you need.** `parse` gives lazy views and builds only the
|
|
66
72
|
values you read; `fields=` extracts only some fields from each document of
|
|
67
73
|
a stream.
|
|
68
74
|
* **Many threads.** On free-threaded Python, streams of documents (NDJSON,
|
|
69
|
-
JSON Lines) are read and written on many threads: up to
|
|
75
|
+
JSON Lines) are read and written on many threads: up to 20 GB/s on 64
|
|
70
76
|
cores. Arrow and MessagePack conversions release the GIL and use many
|
|
71
77
|
threads on any Python: on 32 cores, `loads_arrow` reads NDJSON into Arrow
|
|
72
|
-
at up to
|
|
78
|
+
at up to 27.5 GB/s, 2.3 to 2.9 times as fast as pyarrow.
|
|
73
79
|
* **Arrow without pyarrow.** `loads_arrow` and `dumpb_arrow` convert NDJSON
|
|
74
80
|
to Arrow tables and back, for pyarrow, polars or DuckDB, without a copy.
|
|
75
81
|
* **MessagePack without Python objects.** `json_to_msgpack` and
|
|
76
82
|
`msgpack_to_json` convert directly, without building Python objects.
|
|
83
|
+
* **Minify without parsing.** `minify` strips insignificant whitespace
|
|
84
|
+
and returns `bytes`, without building Python objects.
|
|
77
85
|
* **Everywhere.** No dependencies; wheels for Linux (x64 and ARM), macOS
|
|
78
86
|
(Intel and Apple silicon) and Windows, Python 3.10 to 3.15, including
|
|
79
87
|
free-threaded Python.
|
|
@@ -147,6 +155,84 @@ doc["search_metadata"].as_dict() # convert a subtree, like loads
|
|
|
147
155
|
`json.loads` accepts (an overflowing number, an unpaired surrogate) is
|
|
148
156
|
returned as plain Python objects, as `loads` would return it.
|
|
149
157
|
|
|
158
|
+
### `type=`: typed decoding
|
|
159
|
+
|
|
160
|
+
`loads(data, type=T)` returns the document as an instance of `T`, checked
|
|
161
|
+
on the way. It builds dataclasses straight from the simdjson tape, without
|
|
162
|
+
an intermediate dict, and is 1.5 to 2.1 times as fast as msgspec on one core
|
|
163
|
+
(see [Typed decoding](#typed-decoding)).
|
|
164
|
+
|
|
165
|
+
<picture>
|
|
166
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_typed_dark.png">
|
|
167
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_typed.png" width="80%" alt="JSON to dataclasses on one core, GB/s. twitter.json, a few fields: fastsimdjson 2.60, msgspec Struct 1.52, msgspec dataclasses 1.43, pydantic 0.66, orjson with cattrs 0.55. citm_catalog.json typed in full: fastsimdjson 0.98, msgspec Struct 0.63, msgspec dataclasses 0.47, pydantic 0.19, orjson with cattrs 0.19. GH Archive NDJSON, 6 fields: fastsimdjson 2.05, msgspec Struct 1.30, msgspec dataclasses 1.16, pydantic 0.51, orjson with cattrs 0.42">
|
|
168
|
+
</picture>
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from dataclasses import dataclass, field
|
|
172
|
+
from typing import Literal, Optional
|
|
173
|
+
|
|
174
|
+
@dataclass
|
|
175
|
+
class User:
|
|
176
|
+
id: int
|
|
177
|
+
login: str
|
|
178
|
+
followers: int = 0
|
|
179
|
+
|
|
180
|
+
@dataclass
|
|
181
|
+
class Repo:
|
|
182
|
+
id: int
|
|
183
|
+
name: str
|
|
184
|
+
owner: User
|
|
185
|
+
topics: list[str] = field(default_factory=list)
|
|
186
|
+
visibility: Literal["public", "private"] = "public"
|
|
187
|
+
license: Optional[str] = None
|
|
188
|
+
|
|
189
|
+
repo = fastsimdjson.loads(data, type=Repo)
|
|
190
|
+
repos = fastsimdjson.loads(data, type=list[Repo])
|
|
191
|
+
events = list(fastsimdjson.loads_many(ndjson, type=Repo))
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`type` accepts:
|
|
195
|
+
|
|
196
|
+
* `int`, `float` (an integer becomes a float), `str`, `bool`, `type(None)`
|
|
197
|
+
(JSON `null`; `None` too inside a type, as in `list[None]`), and `Any` or
|
|
198
|
+
`object` (no check: the value as `loads` returns it). `type=None`, the
|
|
199
|
+
default, means no type;
|
|
200
|
+
* `list`, `tuple` (fixed length or `tuple[T, ...]`), `set`, `frozenset`,
|
|
201
|
+
`dict` with `str` keys, and their abstract counterparts (`Sequence`,
|
|
202
|
+
`Mapping`, ...);
|
|
203
|
+
* `Optional[T]`, unions (`int | str`, at most one type per JSON kind; an
|
|
204
|
+
integer goes to `int` rather than to `float`) and `Literal` (of `str`,
|
|
205
|
+
`int`, `bool` and `None`: JSON `1` is not `True`);
|
|
206
|
+
* enums (by value: `str`, `int`, `bool` or `None`), dataclasses (including
|
|
207
|
+
frozen ones and those with `__slots__`), `TypedDict` (from `typing` or
|
|
208
|
+
`typing_extensions`) and `NamedTuple` (from an array);
|
|
209
|
+
* `Annotated`, `NewType` and `type` aliases, and recursive types.
|
|
210
|
+
|
|
211
|
+
Dataclass fields take their defaults (and default factories) when the key
|
|
212
|
+
is missing, keys that are not fields are ignored, `__post_init__` runs, and
|
|
213
|
+
`init=False` fields get their default. The fields are set as the generated
|
|
214
|
+
`__init__` sets them: an `__init__` of your own is not called. A `TypedDict` becomes a `dict` with
|
|
215
|
+
its keys only. A value of the wrong type raises
|
|
216
|
+
`fastsimdjson.ValidationError` (a `ValueError`) with its path:
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
ValidationError: Expected `int`, got `str` - at `$.owner.id`
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
A `ValueError` or `TypeError` raised by `__post_init__` becomes a
|
|
223
|
+
`ValidationError` too, with the path. Invalid JSON raises
|
|
224
|
+
`JSONDecodeError`, and the documents that only `json` accepts (`NaN`, a
|
|
225
|
+
number that overflows a double) are converted the same way, from what
|
|
226
|
+
`json` returns; past what Python's stack allows, those raise
|
|
227
|
+
`RecursionError`, as `json` does. A set of values that cannot be hashed
|
|
228
|
+
(`set[list[int]]`) or a union that contains itself is a `TypeError`. The
|
|
229
|
+
description of each type is computed once and cached (the cache starts over
|
|
230
|
+
past 1024 types, so that types made on the fly do not pile up). `load`,
|
|
231
|
+
`load_file`, `loads_many` and `map_many` accept `type=` too; a
|
|
232
|
+
`ValidationError` ends the iteration of `loads_many`, as any error does. With
|
|
233
|
+
`threads=N` on free-threaded Python, the instances are built on N threads
|
|
234
|
+
(not with `fields=` or `lazy=True`).
|
|
235
|
+
|
|
150
236
|
### `dumps` and `dump`: like `json.dumps`
|
|
151
237
|
|
|
152
238
|
```python
|
|
@@ -194,6 +280,20 @@ serialize dataclasses, `datetime`, `date`, `time`, `UUID`, numpy arrays or
|
|
|
194
280
|
`OPT_PASSTHROUGH_DATACLASS` and `OPT_PASSTHROUGH_DATETIME` were set, and the
|
|
195
281
|
options that concern only these types are accepted and have no effect.
|
|
196
282
|
|
|
283
|
+
### `minify`: strip whitespace without parsing
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
fastsimdjson.minify(b'{ "a" : [1, 2] }') # b'{"a":[1,2]}'
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
`minify(data)` removes insignificant whitespace (spaces, tabs, newlines and
|
|
290
|
+
carriage returns outside of strings) and returns `bytes`. It accepts `bytes`,
|
|
291
|
+
`bytearray`, `memoryview` and `str`. It does not parse the document and does
|
|
292
|
+
not validate it: numbers, escapes, duplicate keys and key order are left as
|
|
293
|
+
they are, and input that is not valid JSON is minified the same way. An
|
|
294
|
+
unterminated string raises `JSONDecodeError` (the minifier does not report
|
|
295
|
+
where the string started, so the position is 0). The call releases the GIL.
|
|
296
|
+
|
|
197
297
|
### `dumpb_many`: NDJSON, on several threads
|
|
198
298
|
|
|
199
299
|
```python
|
|
@@ -276,9 +376,11 @@ documents instead of an iterator. `map_many(fn, data, **kw)` returns
|
|
|
276
376
|
`[fn(doc) for doc in loads_many(data, **kw)]` (`parse_many` with
|
|
277
377
|
`lazy=True`), with `fn` called in the threads. `threads=0` (or `None`) uses
|
|
278
378
|
one thread per processor; small inputs use fewer threads (about one per
|
|
279
|
-
512 KB). The
|
|
280
|
-
|
|
281
|
-
and `
|
|
379
|
+
512 KB). The workers share one counter. Each claims the next 256 KB and
|
|
380
|
+
moves both ends forward to a newline (to the next `\x1e` for `json_seq`);
|
|
381
|
+
the pieces are adjacent. On `lines` and `json_seq` a document is never cut,
|
|
382
|
+
and one longer than 256 KB is parsed with the piece that started before it.
|
|
383
|
+
`threads` works with the formats `"whitespace"`, `"lines"` and `"json_seq"`.
|
|
282
384
|
|
|
283
385
|
The results, and the exceptions, are those of one thread: when a chunk
|
|
284
386
|
contains an error or a document that only `json` accepts, the documents
|
|
@@ -322,9 +424,10 @@ missing key, an index past the end, or a step into a scalar) gives
|
|
|
322
424
|
As with `at_pointer`, a key that appears twice in an object refers to its
|
|
323
425
|
first occurrence. `fields` cannot be combined with `lazy=True`.
|
|
324
426
|
|
|
325
|
-
On 7.6 GB of GitHub events, `map_many` with three fields ran at 2.
|
|
326
|
-
one core of an Intel Xeon Gold 6548N, against
|
|
327
|
-
(`lazy=True`). With 64 threads, it ran at
|
|
427
|
+
On 7.6 GB of GitHub events, `map_many` with three fields ran at 2.2 GB/s on
|
|
428
|
+
one core of an Intel Xeon Gold 6548N, against 1.8 GB/s with lazy views
|
|
429
|
+
(`lazy=True`). With 64 threads (free-threaded Python 3.14.10t), it ran at
|
|
430
|
+
84 GB/s (lazy views: 76 GB/s).
|
|
328
431
|
|
|
329
432
|
### Arrow: `loads_arrow`, `load_arrow_file` and `dumpb_arrow`
|
|
330
433
|
|
|
@@ -354,7 +457,7 @@ once the batches are taken). fastsimdjson does not depend on pyarrow.
|
|
|
354
457
|
|
|
355
458
|
* The schema is a `pyarrow.Schema` (or any object with `__arrow_c_schema__`)
|
|
356
459
|
whose fields are booleans, 64-bit integers, unsigned 64-bit integers,
|
|
357
|
-
doubles, strings, structs and lists of these, or null. A field absent from a
|
|
460
|
+
doubles, strings, timestamps, structs and lists of these, or null. A field absent from a
|
|
358
461
|
record is null; a key absent from the schema is skipped, or an error with
|
|
359
462
|
`error_on_unknown_fields=True`. Skipped values are checked to be valid
|
|
360
463
|
JSON, unless `validate_skipped=False` (then only their structure is).
|
|
@@ -365,6 +468,19 @@ once the batches are taken). fastsimdjson does not depend on pyarrow.
|
|
|
365
468
|
type of its other values and integers become doubles next to other
|
|
366
469
|
numbers; other mixes of types raise `ValueError`. Strings stay strings (no
|
|
367
470
|
timestamps).
|
|
471
|
+
* A timestamp field (`pa.timestamp("us", tz="UTC")`, any unit, with or
|
|
472
|
+
without a time zone) reads ISO 8601 strings, such as the `created_at` of
|
|
473
|
+
GH Archive events (`"2015-01-01T15:00:00Z"`): a date (a four-digit year), then optionally a
|
|
474
|
+
time (`T` or a space, then `15`, `15:00`, `15:00:00` or
|
|
475
|
+
`15:00:00.123456`), then optionally `Z` or an offset (`+05:00`). A time
|
|
476
|
+
without `Z` or an offset is UTC. An integer is a count of units since 1970.
|
|
477
|
+
As with `pyarrow.json.read_json` (which returns the same table from the
|
|
478
|
+
strings it accepts; a lowercase `t` or `z` and a comma before the fraction
|
|
479
|
+
are accepted here too), a fraction
|
|
480
|
+
with more digits than the unit raises `ValueError`, as does an invalid
|
|
481
|
+
date. Reading the timestamps costs next to nothing: GH Archive with
|
|
482
|
+
`created_at` as `timestamp[us, UTC]` reads at 2.11 GB/s on one core, as
|
|
483
|
+
with strings, against 0.45 GB/s for pyarrow and 0.21 GB/s for polars.
|
|
368
484
|
* A new batch starts every `block_size` bytes of input. With `threads=N`
|
|
369
485
|
(`threads=0` or `None`: one per processor), N threads read blocks of
|
|
370
486
|
`block_size` bytes, cut at line ends: a record must then fit on one line.
|
|
@@ -378,11 +494,17 @@ NDJSON `bytes`, one object per row: a `pyarrow.Table`, `RecordBatch`,
|
|
|
378
494
|
relation, an `ArrowStream`, or any object with `__arrow_c_stream__` or
|
|
379
495
|
`__arrow_c_array__`. It writes integers of 8 to 64 bits, floats and doubles
|
|
380
496
|
(as `dumpb` writes them, NaN and infinities as `null`), booleans, strings
|
|
381
|
-
(including large strings and string views),
|
|
382
|
-
|
|
497
|
+
(including large strings and string views), timestamps (ISO 8601 in UTC,
|
|
498
|
+
`"2015-01-01T15:00:00.250000Z"`, with `Z` when the timestamp has a time zone
|
|
499
|
+
and the fraction when it is not zero), dates (`"2015-01-01"`), structs and
|
|
500
|
+
lists (including large and fixed-size lists); other types raise
|
|
501
|
+
`ValueError`. With
|
|
383
502
|
`write_nulls=False`, null fields are omitted. With `threads=N`, N threads
|
|
384
503
|
write ranges of rows into the result. The output reads back with
|
|
385
|
-
`loads_arrow`, and with `loads_many(data, format="lines")
|
|
504
|
+
`loads_arrow`, and with `loads_many(data, format="lines")`, except for
|
|
505
|
+
timestamps and dates outside the years 0000 to 9999: their year is written
|
|
506
|
+
with more digits or a minus sign, which `loads_arrow` does not read (nor
|
|
507
|
+
does pyarrow).
|
|
386
508
|
|
|
387
509
|
These functions release the GIL and run their threads outside Python, with
|
|
388
510
|
or without free threading. They are built on
|
|
@@ -455,12 +577,15 @@ references to the items of the containers they serialize.
|
|
|
455
577
|
### `release`
|
|
456
578
|
|
|
457
579
|
`release()` frees the simdjson parser and the string caches kept by the
|
|
458
|
-
calling thread.
|
|
580
|
+
calling thread. On free-threaded Python, it also has the idle worker threads
|
|
581
|
+
of the parallel streams (`threads=N`) free theirs; a worker busy with a
|
|
582
|
+
stream of another thread does so when it is done. Views returned by `parse`
|
|
583
|
+
remain valid.
|
|
459
584
|
|
|
460
585
|
## Build and test
|
|
461
586
|
|
|
462
587
|
Python 3.10 or newer, and a C++17 compiler (clang, GCC or MSVC). The simdjson
|
|
463
|
-
5.1.1 and simdutf 9.2.1 amalgamations, simdjson_arrow 0.1.
|
|
588
|
+
5.1.1 and simdutf 9.2.1 amalgamations, simdjson_arrow 0.1.5 (NDJSON to Arrow
|
|
464
589
|
and back: `simdjson_arrow.h` and `simdjson_arrow.cpp`) and simdjson_msgpack
|
|
465
590
|
0.1.1 (JSON to MessagePack and back: `simdjson_msgpack.h` and
|
|
466
591
|
`simdjson_msgpack.cpp`), both under the Apache-2.0 license, are already in
|
|
@@ -516,7 +641,8 @@ order; `tests/test_lazy.py` checks the views returned by `parse` the same way,
|
|
|
516
641
|
`tests/test_dumps.py` compares `dumps` with `json.dumps` and `dumpb` with
|
|
517
642
|
orjson (output and exceptions; the orjson comparisons are skipped when orjson
|
|
518
643
|
is not installed, and recorded orjson results are checked either way), and
|
|
519
|
-
`tests/test_stream.py` and `tests/test_files.py` cover streams and files
|
|
644
|
+
`tests/test_stream.py` and `tests/test_files.py` cover streams and files, and
|
|
645
|
+
`tests/test_minify.py` covers `minify`. The suite
|
|
520
646
|
covers scalars, integers past 64 bits, UTF-8 strings at every length from 0 to
|
|
521
647
|
199, the key cache, random documents, rejected input, deep
|
|
522
648
|
nesting, padding at a page boundary, a saturated array count, reference
|
|
@@ -536,7 +662,8 @@ The benchmark scripts need simdjson-data and the `bench` extra (orjson,
|
|
|
536
662
|
jiter, msgspec, pysimdjson, cysimdjson). `bench.py` times `loads` against
|
|
537
663
|
`json.loads`, orjson and jiter, `bench_lazy.py` times `parse` against pysimdjson and
|
|
538
664
|
cysimdjson, `bench_dumps.py` times `dumps` against `json.dumps` and `dumpb`
|
|
539
|
-
against orjson and msgspec,
|
|
665
|
+
against orjson and msgspec, `bench_many.py` times `loads_many`, and
|
|
666
|
+
`bench_minify.py` times `minify` against parsing and serializing again.
|
|
540
667
|
|
|
541
668
|
pip:
|
|
542
669
|
|
|
@@ -546,6 +673,7 @@ python bench.py
|
|
|
546
673
|
python bench_lazy.py
|
|
547
674
|
python bench_dumps.py
|
|
548
675
|
python bench_many.py
|
|
676
|
+
python bench_minify.py
|
|
549
677
|
```
|
|
550
678
|
|
|
551
679
|
uv:
|
|
@@ -556,13 +684,15 @@ python bench.py
|
|
|
556
684
|
python bench_lazy.py
|
|
557
685
|
python bench_dumps.py
|
|
558
686
|
python bench_many.py
|
|
687
|
+
python bench_minify.py
|
|
559
688
|
```
|
|
560
689
|
|
|
561
690
|
## Benchmarks
|
|
562
691
|
|
|
563
|
-
Intel Xeon Gold 6548N (Emerald Rapids), one core
|
|
564
|
-
|
|
565
|
-
|
|
692
|
+
Intel Xeon Gold 6548N (Emerald Rapids), one core unless stated otherwise,
|
|
693
|
+
Python 3.14.10 (free-threaded Python 3.14.10t for the streams on several
|
|
694
|
+
threads), fastsimdjson 1.0.0 (simdjson 5.1.1) built with GCC 16.2, the 22
|
|
695
|
+
files of [simdjson-data](https://github.com/simdjson/simdjson-data). The scripts are in
|
|
566
696
|
this repository and in
|
|
567
697
|
[the blog repository](https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/tree/master/2026/09/pysimdjson).
|
|
568
698
|
|
|
@@ -573,32 +703,32 @@ geometric mean over the 22 files (higher is better).
|
|
|
573
703
|
|
|
574
704
|
<picture>
|
|
575
705
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_loads_dark.png">
|
|
576
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_loads.png" width="80%" alt="Parsing JSON in Python: fastsimdjson loads 0.
|
|
706
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_loads.png" width="80%" alt="Parsing JSON in Python: fastsimdjson loads 0.77 GB/s, orjson 0.60, jiter 0.54, msgspec 0.53, jiter without its string cache 0.44, pysimdjson 0.44, cysimdjson 0.43, ujson 0.37, python-rapidjson 0.24, simplejson 0.23, json 0.22">
|
|
577
707
|
</picture>
|
|
578
708
|
|
|
579
709
|
| parser | GB/s | vs `json.loads` |
|
|
580
710
|
|---|---:|---:|
|
|
581
711
|
| json (standard library) | 0.22 | 1.00× |
|
|
582
|
-
| simplejson 4.
|
|
583
|
-
| python-rapidjson 1.
|
|
584
|
-
| ujson 6.
|
|
585
|
-
| cysimdjson 26.27 | 0.43 | 1.
|
|
586
|
-
| pysimdjson
|
|
587
|
-
| jiter 0.
|
|
588
|
-
|
|
|
589
|
-
|
|
|
590
|
-
| orjson 3.
|
|
591
|
-
| **fastsimdjson `loads`** | **0.
|
|
592
|
-
|
|
593
|
-
fastsimdjson is the fastest on 21 of the 22 files
|
|
594
|
-
`numbers.json`, an array of floating-point numbers
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
712
|
+
| simplejson 4.3.0 | 0.23 | 1.04× |
|
|
713
|
+
| python-rapidjson 1.26 | 0.24 | 1.08× |
|
|
714
|
+
| ujson 6.1.0 | 0.37 | 1.64× |
|
|
715
|
+
| cysimdjson 26.27 | 0.43 | 1.95× |
|
|
716
|
+
| pysimdjson 8.0.0 | 0.44 | 1.97× |
|
|
717
|
+
| jiter 0.19.0 (no string cache) | 0.44 | 1.98× |
|
|
718
|
+
| msgspec 0.22.0 | 0.53 | 2.38× |
|
|
719
|
+
| jiter 0.19.0 (string cache, the default) | 0.54 | 2.43× |
|
|
720
|
+
| orjson 3.13.0 | 0.60 | 2.70× |
|
|
721
|
+
| **fastsimdjson `loads`** | **0.77** | **3.46×** |
|
|
722
|
+
|
|
723
|
+
fastsimdjson is the fastest on 21 of the 22 files. orjson is 12% faster on
|
|
724
|
+
`numbers.json`, an array of floating-point numbers. On numbers, both spend
|
|
725
|
+
most of their time creating Python floats, which costs the same in both:
|
|
726
|
+
simdjson parses the numbers of these files faster than orjson's parser
|
|
727
|
+
(yyjson), but that is a small part of the total. Part of the gain comes from
|
|
728
|
+
pausing the garbage collector while the objects are built. fastsimdjson's
|
|
729
|
+
lead over orjson is 1.28× with the collector enabled and 1.18× with it
|
|
730
|
+
disabled (geometric means); without the collector, orjson is also 3 to 4%
|
|
731
|
+
faster on `canada.json` and `mesh.json`. yyjson 4.0.6 is left out: it
|
|
602
732
|
returns wrong strings for non-ASCII text. jiter (the parser of pydantic)
|
|
603
733
|
caches strings by default; turning the cache off (`cache_mode=False`) makes it
|
|
604
734
|
slower here.
|
|
@@ -616,34 +746,74 @@ and the screen name of the 100 statuses of `twitter.json`:
|
|
|
616
746
|
|
|
617
747
|
<picture>
|
|
618
748
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_parse_dark.png">
|
|
619
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_parse.png" width="80%" alt="Reading part of twitter.json: fastsimdjson parse
|
|
749
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_parse.png" width="80%" alt="Reading part of twitter.json: fastsimdjson parse 156 µs, pysimdjson 169, cysimdjson 235, msgspec 337, fastsimdjson loads 844, orjson 971, jiter 1156, jiter without its string cache 1602, json 3977">
|
|
620
750
|
</picture>
|
|
621
751
|
|
|
622
752
|
| method | µs |
|
|
623
753
|
|---|---:|
|
|
624
|
-
| `json.loads` |
|
|
625
|
-
| jiter (no string cache) |
|
|
626
|
-
| jiter (string cache) |
|
|
627
|
-
| orjson |
|
|
628
|
-
| fastsimdjson `loads` |
|
|
629
|
-
| msgspec (typed `Struct`) |
|
|
630
|
-
| cysimdjson (lazy) |
|
|
631
|
-
| pysimdjson (lazy) |
|
|
632
|
-
| **fastsimdjson `parse`** | **
|
|
633
|
-
|
|
634
|
-
Here `parse` is about 25 times faster than `json.loads` and 5.
|
|
754
|
+
| `json.loads` | 3977 |
|
|
755
|
+
| jiter (no string cache) | 1602 |
|
|
756
|
+
| jiter (string cache) | 1156 |
|
|
757
|
+
| orjson | 971 |
|
|
758
|
+
| fastsimdjson `loads` | 844 |
|
|
759
|
+
| msgspec (typed `Struct`) | 337 |
|
|
760
|
+
| cysimdjson (lazy) | 235 |
|
|
761
|
+
| pysimdjson (lazy) | 169 |
|
|
762
|
+
| **fastsimdjson `parse`** | **156** |
|
|
763
|
+
|
|
764
|
+
Here `parse` is about 25 times faster than `json.loads` and 5.4 times faster
|
|
635
765
|
than `loads`. Most of its time is the simdjson parse itself.
|
|
636
766
|
|
|
767
|
+
### Typed decoding
|
|
768
|
+
|
|
769
|
+
`loads(data, type=T)` against msgspec (`msgspec.json.Decoder(T)` with the
|
|
770
|
+
same dataclasses, and with the equivalent `msgspec.Struct` classes), pydantic
|
|
771
|
+
(`TypeAdapter(...).validate_json`, with the equivalent models) and
|
|
772
|
+
`cattrs.structure(orjson.loads(data), T)`. Three cases:
|
|
773
|
+
|
|
774
|
+
* **twitter:** `twitter.json` as a dataclass of 100 statuses, six fields of
|
|
775
|
+
each status and four of its user, the rest skipped.
|
|
776
|
+
* **citm:** `citm_catalog.json` typed in full (dicts of dataclasses, lists of
|
|
777
|
+
nested dataclasses).
|
|
778
|
+
* **gh:** 64 MB of GH Archive events (NDJSON), six fields of each event
|
|
779
|
+
(`loads_many(data, type=T)`, one call per line for the others).
|
|
780
|
+
|
|
781
|
+
MB/s, one core of an Intel Xeon Gold 6548N, Python 3.14.10, best of 3 runs
|
|
782
|
+
of 7 (`python bench_typed.py simdjson-data/jsonexamples gharchive.ndjson`):
|
|
783
|
+
|
|
784
|
+
<picture>
|
|
785
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_typed_dark.png">
|
|
786
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_typed.png" width="80%" alt="JSON to dataclasses on one core, GB/s. twitter.json, a few fields: fastsimdjson 2.60, msgspec Struct 1.52, msgspec dataclasses 1.43, pydantic 0.66, orjson with cattrs 0.55. citm_catalog.json typed in full: fastsimdjson 0.98, msgspec Struct 0.63, msgspec dataclasses 0.47, pydantic 0.19, orjson with cattrs 0.19. GH Archive NDJSON, 6 fields: fastsimdjson 2.05, msgspec Struct 1.30, msgspec dataclasses 1.16, pydantic 0.51, orjson with cattrs 0.42">
|
|
787
|
+
</picture>
|
|
788
|
+
|
|
789
|
+
| | twitter | citm | gh |
|
|
790
|
+
|---|---:|---:|---:|
|
|
791
|
+
| **fastsimdjson `loads(type=)`** | **2597** | **981** | **2055** |
|
|
792
|
+
| msgspec (Struct) | 1520 | 632 | 1296 |
|
|
793
|
+
| msgspec (dataclass) | 1428 | 467 | 1156 |
|
|
794
|
+
| pydantic 2.14 | 659 | 192 | 514 |
|
|
795
|
+
| orjson + cattrs | 553 | 187 | 420 |
|
|
796
|
+
| fastsimdjson `loads` (dicts, untyped) | 933 | 1074 | 431 |
|
|
797
|
+
|
|
798
|
+
fastsimdjson is 1.5 to 1.7 times as fast as msgspec with Structs, 1.8 to 2.1
|
|
799
|
+
times as fast with the same dataclasses, and 3.9 to 5.1 times as fast as
|
|
800
|
+
pydantic. When most of the document is not needed (twitter, gh), typed
|
|
801
|
+
decoding is also 2.8 to 4.8 times as fast as building the dicts.
|
|
802
|
+
|
|
803
|
+
On free-threaded Python 3.14.10t, `loads_many(data, type=T, threads=N)` read
|
|
804
|
+
the 886 MB GH Archive file into dataclasses at 1.82 GB/s on one thread,
|
|
805
|
+
12.0 GB/s on 8 and 33.3 GB/s on 32.
|
|
806
|
+
|
|
637
807
|
### `dumps` against `json.dumps`
|
|
638
808
|
|
|
639
809
|
<picture>
|
|
640
810
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumps_dark.png">
|
|
641
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumps.png" width="80%" alt="Writing JSON as str: fastsimdjson dumps 4.
|
|
811
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumps.png" width="80%" alt="Writing JSON as str: fastsimdjson dumps 4.21 times faster than json.dumps">
|
|
642
812
|
</picture>
|
|
643
813
|
|
|
644
|
-
`dumps` returns exactly the `str` of `json.dumps` and is 4.
|
|
645
|
-
(geometric mean over the 22 files; from
|
|
646
|
-
|
|
814
|
+
`dumps` returns exactly the `str` of `json.dumps` and is 4.2 times faster
|
|
815
|
+
(geometric mean over the 22 files; from 2.7 times on `citm_catalog.json` to
|
|
816
|
+
10.5 times on `canada.json`).
|
|
647
817
|
|
|
648
818
|
### `dumpb` against orjson and msgspec
|
|
649
819
|
|
|
@@ -651,43 +821,71 @@ than `loads`. Most of its time is the simdjson parse itself.
|
|
|
651
821
|
`bytes`; `dumpb` and orjson produce identical bytes on every file. With the
|
|
652
822
|
standard library, the same compact bytes come from
|
|
653
823
|
`json.dumps(obj, separators=(",", ":"), ensure_ascii=False).encode()`.
|
|
654
|
-
|
|
824
|
+
Each call encodes a fresh copy of the document (`bench_dumps.py`), so no
|
|
825
|
+
encoder gains from what it cached on the objects at a previous call. One
|
|
826
|
+
core of an Intel Xeon Gold 6548N, Python 3.14.10, GCC 16.2, fastsimdjson
|
|
827
|
+
1.0.0, orjson 3.13.0, msgspec 0.22.0. Microseconds:
|
|
655
828
|
|
|
656
829
|
<picture>
|
|
657
830
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumpb_dark.png">
|
|
658
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumpb.png" width="80%" alt="Writing JSON as bytes, speed relative to json.dumps(...).encode(): fastsimdjson dumpb
|
|
831
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumpb.png" width="80%" alt="Writing JSON as bytes, speed relative to json.dumps(...).encode(): fastsimdjson dumpb 7.95x, orjson 7.38x, msgspec 5.26x">
|
|
659
832
|
</picture>
|
|
660
833
|
|
|
661
834
|
| file | `json.dumps(...).encode()` | fastsimdjson `dumpb` | orjson | msgspec |
|
|
662
835
|
|---|---:|---:|---:|---:|
|
|
663
|
-
| twitter |
|
|
664
|
-
| citm_catalog |
|
|
665
|
-
| github_events |
|
|
666
|
-
| gsoc-2018 |
|
|
667
|
-
| update-center |
|
|
668
|
-
| canada |
|
|
669
|
-
| mesh |
|
|
670
|
-
| numbers |
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
(`
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
836
|
+
| twitter | 1804 | 258 | 313 | 387 |
|
|
837
|
+
| citm_catalog | 3114 | 651 | 666 | 716 |
|
|
838
|
+
| github_events | 211 | 21 | 20 | 32 |
|
|
839
|
+
| gsoc-2018 | 12153 | 956 | 1165 | 2095 |
|
|
840
|
+
| update-center | 2647 | 309 | 298 | 514 |
|
|
841
|
+
| canada | 37821 | 2743 | 2480 | 3978 |
|
|
842
|
+
| mesh | 8903 | 876 | 1049 | 1401 |
|
|
843
|
+
| numbers | 2473 | 201 | 204 | 332 |
|
|
844
|
+
|
|
845
|
+
Over the 22 files, `dumpb` is 8% faster than orjson (geometric mean), from
|
|
846
|
+
10% slower on `canada.json` (mostly floating-point numbers) and up to 6%
|
|
847
|
+
slower on the smallest files (`twitter_api_response.json`,
|
|
848
|
+
`github_events.json`) to 22% faster on `gsoc-2018.json`, whose strings are
|
|
849
|
+
mostly not ASCII, and 35% faster on `semanticscholar-corpus.json`. `dumpb` is
|
|
850
|
+
1.5 times faster than msgspec (orjson 1.4 times) and 8 times faster than
|
|
851
|
+
`json`. The comparison was run on a processor
|
|
852
|
+
with AVX-512, which `dumpb` and orjson both use to escape strings; other x64
|
|
853
|
+
processors use SSE2 and ARM processors NEON.
|
|
854
|
+
|
|
855
|
+
### `minify`
|
|
856
|
+
|
|
857
|
+
`minify` only removes whitespace. The other columns parse the document and
|
|
858
|
+
serialize it again, which also validates it and rewrites numbers. Geometric
|
|
859
|
+
mean over the 22 files, one core of an Intel Xeon Gold 6548N, Python 3.14.10,
|
|
860
|
+
GCC 16.2, orjson 3.13.0 (`bench_minify.py`):
|
|
861
|
+
|
|
862
|
+
<picture>
|
|
863
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_minify_dark.png">
|
|
864
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_minify.png" width="80%" alt="Minifying JSON in Python: fastsimdjson minify 18.64 GB/s, fastsimdjson dumpb(loads(s)) 0.54, orjson dumps(loads(s)) 0.44, json dumps(loads(s)) 0.11">
|
|
865
|
+
</picture>
|
|
866
|
+
|
|
867
|
+
| method | GB/s |
|
|
868
|
+
|---|---:|
|
|
869
|
+
| **fastsimdjson `minify`** | **18.64** |
|
|
870
|
+
| `loads` + `dumpb` | 0.54 |
|
|
871
|
+
| orjson `loads` + `dumps` | 0.44 |
|
|
872
|
+
| `json.loads` + `json.dumps` | 0.11 |
|
|
873
|
+
|
|
874
|
+
Per file, `minify` runs from 15.4 GB/s (`canada.json`) to 20.7 GB/s
|
|
875
|
+
(`apache_builds.json`).
|
|
679
876
|
|
|
680
877
|
### Writing NDJSON with `dumpb_many`
|
|
681
878
|
|
|
682
879
|
The 593,945 events of two hours of [GH Archive](https://www.gharchive.org/)
|
|
683
880
|
(1.87 GB of NDJSON), written back as NDJSON from Python objects. With the
|
|
684
|
-
GIL (Python 3.14.
|
|
685
|
-
at 0.
|
|
686
|
-
1.
|
|
881
|
+
GIL (Python 3.14.10), one thread: `orjson.dumps` on each record, joined, runs
|
|
882
|
+
at 0.93 GB/s, `dumpb` on each record at 0.93 GB/s, and `dumpb_many` at
|
|
883
|
+
1.49 GB/s. On free-threaded Python 3.14.10t, GB/s (up to 32 threads on the
|
|
884
|
+
cores of one socket, 64 on both):
|
|
687
885
|
|
|
688
886
|
| threads | 1 | 8 | 32 | 64 |
|
|
689
887
|
|---|---:|---:|---:|---:|
|
|
690
|
-
| `dumpb_many(records, threads=N)` | 1.
|
|
888
|
+
| `dumpb_many(records, threads=N)` | 1.48 | 5.6 | 11.6 | 10.5 |
|
|
691
889
|
|
|
692
890
|
### NDJSON to Arrow and back
|
|
693
891
|
|
|
@@ -697,52 +895,52 @@ structs; the rest of each event is skipped), or inferring the schema. Reading
|
|
|
697
895
|
gives a `pyarrow.Table` (`pyarrow.table(fastsimdjson.loads_arrow(data,
|
|
698
896
|
schema, threads=N))`); the time includes the import into pyarrow. Writing
|
|
699
897
|
starts from that table: fastsimdjson `dumpb_arrow`, polars `write_ndjson` and
|
|
700
|
-
DuckDB `COPY ... TO` (on tmpfs). Python 3.14, pyarrow 26.0, polars 2.1,
|
|
701
|
-
2.0, fastsimdjson 0.
|
|
702
|
-
|
|
898
|
+
DuckDB `COPY ... TO` (on tmpfs). Python 3.14.10, pyarrow 26.0, polars 2.1,
|
|
899
|
+
DuckDB 2.0, fastsimdjson 1.0.0, Intel Xeon Gold 6548N (up to 32 threads on
|
|
900
|
+
the 32 cores of one socket; 64 threads on both sockets).
|
|
703
901
|
|
|
704
902
|
<picture>
|
|
705
903
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_1_dark.png">
|
|
706
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_1.png" width="80%" alt="Reading NDJSON into a pyarrow.Table on one thread: flat, fastsimdjson 0.
|
|
904
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_1.png" width="80%" alt="Reading NDJSON into a pyarrow.Table on one thread: flat, fastsimdjson 0.76 GB/s, pyarrow 0.18, polars 0.27; GH Archive, fastsimdjson 1.96, pyarrow 0.46, polars 0.54; flat with an inferred schema, fastsimdjson 0.79, pyarrow 0.18, polars 0.09">
|
|
707
905
|
</picture>
|
|
708
906
|
|
|
709
907
|
<picture>
|
|
710
908
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_32_dark.png">
|
|
711
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_32.png" width="80%" alt="Reading NDJSON into a pyarrow.Table on 32 threads: flat, fastsimdjson
|
|
909
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_32.png" width="80%" alt="Reading NDJSON into a pyarrow.Table on 32 threads: flat, fastsimdjson 15.0 GB/s, pyarrow 5.3, polars 4.3; GH Archive, fastsimdjson 27.5, pyarrow 12.1, polars 4.0; flat with an inferred schema, fastsimdjson 14.4, pyarrow 5.0, polars 0.12">
|
|
712
910
|
</picture>
|
|
713
911
|
|
|
714
912
|
<picture>
|
|
715
913
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_1_dark.png">
|
|
716
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_1.png" width="80%" alt="Writing a pyarrow.Table as NDJSON on one thread: flat, fastsimdjson 0.
|
|
914
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_1.png" width="80%" alt="Writing a pyarrow.Table as NDJSON on one thread: flat, fastsimdjson 0.92 GB/s, polars 0.45, DuckDB 0.32; GH Archive, fastsimdjson 1.08, polars 0.46, DuckDB 0.32">
|
|
717
915
|
</picture>
|
|
718
916
|
|
|
719
917
|
<picture>
|
|
720
918
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_32_dark.png">
|
|
721
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_32.png" width="80%" alt="Writing a pyarrow.Table as NDJSON on 32 threads: flat, fastsimdjson
|
|
919
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_32.png" width="80%" alt="Writing a pyarrow.Table as NDJSON on 32 threads: flat, fastsimdjson 9.6 GB/s, polars 1.6, DuckDB 4.8; GH Archive, fastsimdjson 4.8, polars 0.86, DuckDB 1.1">
|
|
722
920
|
</picture>
|
|
723
921
|
|
|
724
922
|
All the numbers, in GB/s:
|
|
725
923
|
|
|
726
924
|
| | threads | 1 | 8 | 32 | 64 |
|
|
727
925
|
|---|---|---:|---:|---:|---:|
|
|
728
|
-
| flat, read | fastsimdjson `loads_arrow` | **0.
|
|
729
|
-
| | pyarrow `read_json` | 0.18 | 1.4 | 5.3 | 7.
|
|
730
|
-
| | polars `read_ndjson` | 0.27 | 2.0 | 4.3 | 3.
|
|
731
|
-
| flat, read, inferring the schema | fastsimdjson `loads_arrow` | **0.
|
|
732
|
-
| | pyarrow `read_json` | 0.18 | 1.4 | 5.0 | 6.
|
|
926
|
+
| flat, read | fastsimdjson `loads_arrow` | **0.76** | **5.7** | **15.0** | **18.0** |
|
|
927
|
+
| | pyarrow `read_json` | 0.18 | 1.4 | 5.3 | 7.8 |
|
|
928
|
+
| | polars `read_ndjson` | 0.27 | 2.0 | 4.3 | 3.1 |
|
|
929
|
+
| flat, read, inferring the schema | fastsimdjson `loads_arrow` | **0.79** | **5.6** | **14.4** | **12.5** |
|
|
930
|
+
| | pyarrow `read_json` | 0.18 | 1.4 | 5.0 | 6.8 |
|
|
733
931
|
| | polars `read_ndjson` | 0.09 | 0.12 | 0.12 | 0.12 |
|
|
734
|
-
| GH Archive, read | fastsimdjson `loads_arrow` | **
|
|
735
|
-
| | pyarrow `read_json` | 0.46 | 3.5 | 12.
|
|
736
|
-
| | polars `read_ndjson` | 0.
|
|
737
|
-
| flat, write | fastsimdjson `dumpb_arrow` | **0.
|
|
738
|
-
| | polars | 0.45 | 1.
|
|
739
|
-
| | DuckDB | 0.
|
|
740
|
-
| GH Archive, write | fastsimdjson `dumpb_arrow` | **1.
|
|
741
|
-
| | polars | 0.46 |
|
|
742
|
-
| | DuckDB | 0.
|
|
743
|
-
|
|
744
|
-
`load_arrow_file` on the same files, from the page cache, reads at 0.
|
|
745
|
-
1.5 GB/s on one thread, 9.
|
|
932
|
+
| GH Archive, read | fastsimdjson `loads_arrow` | **1.96** | **12.9** | **27.5** | **24.3** |
|
|
933
|
+
| | pyarrow `read_json` | 0.46 | 3.5 | 12.1 | 14.5 |
|
|
934
|
+
| | polars `read_ndjson` | 0.54 | 3.5 | 4.0 | 3.1 |
|
|
935
|
+
| flat, write | fastsimdjson `dumpb_arrow` | **0.92** | **3.7** | **9.6** | **12.1** |
|
|
936
|
+
| | polars | 0.45 | 1.1 | 1.6 | 1.5 |
|
|
937
|
+
| | DuckDB | 0.32 | 2.3 | 4.8 | 3.4 |
|
|
938
|
+
| GH Archive, write | fastsimdjson `dumpb_arrow` | **1.08** | **3.0** | **4.8** | **4.2** |
|
|
939
|
+
| | polars | 0.46 | 0.52 | 0.86 | 1.06 |
|
|
940
|
+
| | DuckDB | 0.32 | 1.3 | 1.1 | 0.86 |
|
|
941
|
+
|
|
942
|
+
`load_arrow_file` on the same files, from the page cache, reads at 0.69 and
|
|
943
|
+
1.5 GB/s on one thread, 9.1 and 13.0 GB/s on 32 threads. The benchmark is
|
|
746
944
|
`THREADS=N python bench_arrow.py flat.ndjson:flat gharchive.ndjson:gh
|
|
747
945
|
flat.ndjson:infer`; `path:infer` times any NDJSON file without a schema. The
|
|
748
946
|
flat file comes from
|
|
@@ -758,17 +956,17 @@ Python, which decode into Python objects, then encode them:
|
|
|
758
956
|
`ormsgpack.packb(orjson.loads(s))`, `msgspec.msgpack.encode(msgspec.json.decode(s))`
|
|
759
957
|
and so on. The 22 files of simdjson-data, geometric means of the speeds, in
|
|
760
958
|
GB/s of JSON (read when writing MessagePack, written when writing JSON).
|
|
761
|
-
Python 3.14, msgpack 1.2, orjson 3.13, ormsgpack 1.13, msgspec 0.22, Intel
|
|
762
|
-
Xeon Gold
|
|
959
|
+
Python 3.14.10, msgpack 1.2, orjson 3.13, ormsgpack 1.13, msgspec 0.22, Intel
|
|
960
|
+
Xeon Gold 6548N, one core.
|
|
763
961
|
|
|
764
962
|
<picture>
|
|
765
963
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_encode_dark.png">
|
|
766
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_encode.png" width="80%" alt="JSON to MessagePack in Python, geometric mean over the 22 files of simdjson-data: fastsimdjson json_to_msgpack 1.
|
|
964
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_encode.png" width="80%" alt="JSON to MessagePack in Python, geometric mean over the 22 files of simdjson-data: fastsimdjson json_to_msgpack 1.67 GB/s, orjson with ormsgpack 0.46, msgspec 0.42, fastsimdjson loads with msgpack 0.34, orjson with msgpack 0.32, json with msgpack 0.17">
|
|
767
965
|
</picture>
|
|
768
966
|
|
|
769
967
|
<picture>
|
|
770
968
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_decode_dark.png">
|
|
771
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_decode.png" width="80%" alt="MessagePack to JSON in Python, geometric mean over the 22 files of simdjson-data: fastsimdjson msgpack_to_json
|
|
969
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_decode.png" width="80%" alt="MessagePack to JSON in Python, geometric mean over the 22 files of simdjson-data: fastsimdjson msgpack_to_json 1.43 GB/s, ormsgpack with orjson 0.35, msgspec 0.32, msgpack with fastsimdjson dumpb 0.26, msgpack with orjson 0.26, msgpack with json 0.10">
|
|
772
970
|
</picture>
|
|
773
971
|
|
|
774
972
|
Streams: the 304,929 events of an hour of GH Archive (886 MB of NDJSON), with
|
|
@@ -780,13 +978,13 @@ sockets):
|
|
|
780
978
|
|
|
781
979
|
<picture>
|
|
782
980
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_ndjson_dark.png">
|
|
783
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_ndjson.png" width="80%" alt="GH Archive NDJSON to MessagePack: fastsimdjson
|
|
981
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_ndjson.png" width="80%" alt="GH Archive NDJSON to MessagePack: fastsimdjson 22.7 GB/s on 64 threads, 16.0 on 32, 8.7 on 8, 1.31 on one thread, orjson with ormsgpack 0.36 on one thread; MessagePack to NDJSON: fastsimdjson 6.0 GB/s on 8 threads, 1.51 on one thread, msgpack with orjson 0.25">
|
|
784
982
|
</picture>
|
|
785
983
|
|
|
786
984
|
| threads | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
|
|
787
985
|
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
788
|
-
| NDJSON to MessagePack | 1.
|
|
789
|
-
| MessagePack to NDJSON | 1.
|
|
986
|
+
| NDJSON to MessagePack | 1.31 | 2.45 | 4.7 | 8.7 | 14.0 | 16.0 | 22.7 |
|
|
987
|
+
| MessagePack to NDJSON | 1.51 | 2.26 | 4.4 | 6.0 | 6.0 | 6.0 | 5.9 |
|
|
790
988
|
|
|
791
989
|
MessagePack to NDJSON stops scaling at about eight threads: one thread must
|
|
792
990
|
find where the values end (MessagePack has no line ends) before the others
|
|
@@ -802,40 +1000,40 @@ files; best of three runs:
|
|
|
802
1000
|
|
|
803
1001
|
<picture>
|
|
804
1002
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_ndjson_dark.png">
|
|
805
|
-
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_ndjson.png" width="80%" alt="Reading NDJSON: fastsimdjson parse_many
|
|
1003
|
+
<img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_ndjson.png" width="80%" alt="Reading NDJSON: fastsimdjson parse_many 1.13 GB/s, loads_many 0.40, msgspec decode_lines 0.36, fastsimdjson loads per line 0.34, orjson per line 0.26, msgspec decode per line 0.26, jiter per line 0.23, jiter without its string cache per line 0.21, json per line 0.12">
|
|
806
1004
|
</picture>
|
|
807
1005
|
|
|
808
1006
|
| method | ms | GB/s |
|
|
809
1007
|
|---|---:|---:|
|
|
810
|
-
| `json.loads` on each line |
|
|
811
|
-
| jiter on each line (no string cache) |
|
|
812
|
-
| jiter on each line (string cache) |
|
|
813
|
-
|
|
|
814
|
-
|
|
|
815
|
-
| fastsimdjson `loads` on each line |
|
|
816
|
-
| msgspec `decode_lines` |
|
|
817
|
-
| fastsimdjson `loads_many` |
|
|
818
|
-
| fastsimdjson `parse_many` (views only) |
|
|
819
|
-
|
|
820
|
-
msgspec's `decode_lines
|
|
821
|
-
faster). `parse_many` only creates the views; reading values from them adds to
|
|
1008
|
+
| `json.loads` on each line | 164 | 0.12 |
|
|
1009
|
+
| jiter on each line (no string cache) | 94 | 0.21 |
|
|
1010
|
+
| jiter on each line (string cache) | 84 | 0.23 |
|
|
1011
|
+
| msgspec `decode` on each line | 75 | 0.26 |
|
|
1012
|
+
| orjson on each line | 74 | 0.26 |
|
|
1013
|
+
| fastsimdjson `loads` on each line | 58 | 0.34 |
|
|
1014
|
+
| msgspec `decode_lines` | 55 | 0.36 |
|
|
1015
|
+
| fastsimdjson `loads_many` | 49 | 0.40 |
|
|
1016
|
+
| fastsimdjson `parse_many` (views only) | 17 | 1.13 |
|
|
1017
|
+
|
|
1018
|
+
`loads_many` is 13% faster than msgspec's `decode_lines`. `parse_many` only creates the views; reading values from them adds to
|
|
822
1019
|
its time.
|
|
823
1020
|
|
|
824
1021
|
### Streams on several threads
|
|
825
1022
|
|
|
826
1023
|
300 MB of NDJSON (146,624 records: tweets, GitHub events, citm performances,
|
|
827
|
-
gsoc and update-center entries), free-threaded Python 3.14.
|
|
1024
|
+
gsoc and update-center entries), free-threaded Python 3.14.10t, collector
|
|
828
1025
|
disabled (see below), Intel Xeon Gold 6548N (64 cores); GB/s:
|
|
829
1026
|
|
|
830
1027
|
| threads | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
|
|
831
1028
|
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
832
|
-
| `map_many(len, data, threads=N)` |
|
|
833
|
-
| `parse_many(data, threads=N)` |
|
|
834
|
-
| `loads_many(data, threads=N)` | 0.
|
|
835
|
-
|
|
836
|
-
`map_many` is
|
|
837
|
-
|
|
838
|
-
|
|
1029
|
+
| `map_many(len, data, threads=N)` | 0.90 | 1.64 | 2.08 | 3.53 | 5.85 | 8.70 | 16.8 |
|
|
1030
|
+
| `parse_many(data, threads=N)` | 1.59 | 2.78 | 3.75 | 4.79 | 9.01 | 13.5 | **20.6** |
|
|
1031
|
+
| `loads_many(data, threads=N)` | 0.77 | 1.52 | 2.29 | 4.08 | 6.87 | 9.99 | 11.8 |
|
|
1032
|
+
|
|
1033
|
+
`map_many` is 19 times faster on 64 threads than on one, and `parse_many` 13
|
|
1034
|
+
times. `loads_many` builds every document for the calling thread and is 15
|
|
1035
|
+
times faster. On 64 threads, these numbers vary by up to a third from one
|
|
1036
|
+
run to the next. With the collector enabled,
|
|
839
1037
|
Python collects after the call returns: it examines the millions of objects
|
|
840
1038
|
just created, which takes about 0.1 s here, with or without threads.
|
|
841
1039
|
|
|
@@ -843,7 +1041,17 @@ just created, which takes about 0.1 s here, with or without threads.
|
|
|
843
1041
|
|
|
844
1042
|
* The simdjson parser and the key and string caches are thread-local.
|
|
845
1043
|
`release()` frees the parser and the cached strings retained by the calling
|
|
846
|
-
thread
|
|
847
|
-
|
|
1044
|
+
thread and by the worker threads of the parallel streams, and they are
|
|
1045
|
+
freed when a Python thread exits. A parser that grows past 64 MB is freed
|
|
1046
|
+
on its own at the end of that call; its caches stay.
|
|
1047
|
+
* On free-threaded Python, the worker threads of the parallel streams
|
|
1048
|
+
(`threads=N`) are started at the first call that needs them and kept until
|
|
1049
|
+
the interpreter exits: starting threads costs about as much as the parsing.
|
|
1050
|
+
Idle workers wait without using the processor. Each one keeps a parser
|
|
1051
|
+
(about a megabyte) and its caches until `release()`. Free-threaded CPython
|
|
1052
|
+
also keeps the memory of freed objects for reuse, in the thread that
|
|
1053
|
+
allocated it, rather than returning it to the system (the standard `json`
|
|
1054
|
+
module shows the same): after a large threaded call, the process stays
|
|
1055
|
+
larger, and the next calls reuse that memory.
|
|
848
1056
|
* Subinterpreters are not supported: the module keeps per-process state (its
|
|
849
1057
|
types, and per-thread parsers and string caches).
|