fastsimdjson 0.10.3__tar.gz → 2.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.
Files changed (36) hide show
  1. {fastsimdjson-0.10.3/src/fastsimdjson.egg-info → fastsimdjson-2.0.0}/PKG-INFO +397 -137
  2. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/README.md +392 -135
  3. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/pyproject.toml +18 -4
  4. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/setup.py +1 -1
  5. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/src/fastsimdjson.cpp +1223 -148
  6. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0/src/fastsimdjson.egg-info}/PKG-INFO +397 -137
  7. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/src/fastsimdjson.egg-info/SOURCES.txt +4 -0
  8. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/src/fastsimdjson.egg-info/requires.txt +3 -0
  9. fastsimdjson-2.0.0/src/typed.h +1202 -0
  10. fastsimdjson-2.0.0/tests/conftest.py +21 -0
  11. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/tests/test_arrow.py +74 -2
  12. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/tests/test_dumps.py +10 -2
  13. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/tests/test_lazy.py +1 -0
  14. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/tests/test_loads.py +5 -0
  15. fastsimdjson-2.0.0/tests/test_minify.py +165 -0
  16. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/tests/test_msgpack.py +1 -0
  17. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/tests/test_stream.py +349 -0
  18. fastsimdjson-2.0.0/tests/test_typed.py +638 -0
  19. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdjson_arrow.cpp +306 -6
  20. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdjson_arrow.h +41 -9
  21. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/MANIFEST.in +0 -0
  22. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/setup.cfg +0 -0
  23. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/src/fastsimdjson.egg-info/dependency_links.txt +0 -0
  24. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/src/fastsimdjson.egg-info/top_level.txt +0 -0
  25. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/tests/test_files.py +0 -0
  26. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdjson.cpp +0 -0
  27. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdjson.h +0 -0
  28. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdjson_arrow-LICENSE +0 -0
  29. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdjson_msgpack-LICENSE +0 -0
  30. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdjson_msgpack.cpp +0 -0
  31. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdjson_msgpack.h +0 -0
  32. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdutf.cpp +0 -0
  33. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdutf.h +0 -0
  34. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/simdutf_c.h +0 -0
  35. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/zmij-LICENSE +0 -0
  36. {fastsimdjson-0.10.3 → fastsimdjson-2.0.0}/vendor/zmij.h +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastsimdjson
3
- Version: 0.10.3
3
+ Version: 2.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 :: 4 - Beta
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.6 times faster, and it goes further: lazy
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.6 times json.dumps; JSON to MessagePack, 3.9 times orjson with ormsgpack; NDJSON to Arrow, 3.8 times polars; MessagePack to JSON, 3.5 times ormsgpack with orjson; Arrow to NDJSON, 2.4 times polars; a few fields of a document, 2.1 times msgspec; JSON to Python objects, 1.3 times orjson">
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 28 GB/s on 64
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 29.7 GB/s, 2.4 to 2.8 times as fast as pyarrow.
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.
@@ -95,6 +103,17 @@ uv pip install fastsimdjson # in a uv project: uv add fastsimdjson
95
103
  Wheels are available for Linux, macOS and Windows, for Python 3.10 to 3.15,
96
104
  including free-threaded Python 3.14 and 3.15.
97
105
 
106
+ Wheels are also available for Pyodide (WebAssembly, in the browser or in
107
+ Node), for Python 3.13 to 3.15:
108
+
109
+ ```python
110
+ import micropip
111
+ await micropip.install("fastsimdjson")
112
+ ```
113
+
114
+ Under Pyodide, Python cannot start threads: `threads=` runs on the calling
115
+ thread.
116
+
98
117
  ## Usage
99
118
 
100
119
  ### `loads`: the whole document
@@ -147,6 +166,84 @@ doc["search_metadata"].as_dict() # convert a subtree, like loads
147
166
  `json.loads` accepts (an overflowing number, an unpaired surrogate) is
148
167
  returned as plain Python objects, as `loads` would return it.
149
168
 
169
+ ### `type=`: typed decoding
170
+
171
+ `loads(data, type=T)` returns the document as an instance of `T`, checked
172
+ on the way. It builds dataclasses straight from the simdjson tape, without
173
+ an intermediate dict, and is 1.5 to 2.1 times as fast as msgspec on one core
174
+ (see [Typed decoding](#typed-decoding)).
175
+
176
+ <picture>
177
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_typed_dark.png">
178
+ <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">
179
+ </picture>
180
+
181
+ ```python
182
+ from dataclasses import dataclass, field
183
+ from typing import Literal, Optional
184
+
185
+ @dataclass
186
+ class User:
187
+ id: int
188
+ login: str
189
+ followers: int = 0
190
+
191
+ @dataclass
192
+ class Repo:
193
+ id: int
194
+ name: str
195
+ owner: User
196
+ topics: list[str] = field(default_factory=list)
197
+ visibility: Literal["public", "private"] = "public"
198
+ license: Optional[str] = None
199
+
200
+ repo = fastsimdjson.loads(data, type=Repo)
201
+ repos = fastsimdjson.loads(data, type=list[Repo])
202
+ events = list(fastsimdjson.loads_many(ndjson, type=Repo))
203
+ ```
204
+
205
+ `type` accepts:
206
+
207
+ * `int`, `float` (an integer becomes a float), `str`, `bool`, `type(None)`
208
+ (JSON `null`; `None` too inside a type, as in `list[None]`), and `Any` or
209
+ `object` (no check: the value as `loads` returns it). `type=None`, the
210
+ default, means no type;
211
+ * `list`, `tuple` (fixed length or `tuple[T, ...]`), `set`, `frozenset`,
212
+ `dict` with `str` keys, and their abstract counterparts (`Sequence`,
213
+ `Mapping`, ...);
214
+ * `Optional[T]`, unions (`int | str`, at most one type per JSON kind; an
215
+ integer goes to `int` rather than to `float`) and `Literal` (of `str`,
216
+ `int`, `bool` and `None`: JSON `1` is not `True`);
217
+ * enums (by value: `str`, `int`, `bool` or `None`), dataclasses (including
218
+ frozen ones and those with `__slots__`), `TypedDict` (from `typing` or
219
+ `typing_extensions`) and `NamedTuple` (from an array);
220
+ * `Annotated`, `NewType` and `type` aliases, and recursive types.
221
+
222
+ Dataclass fields take their defaults (and default factories) when the key
223
+ is missing, keys that are not fields are ignored, `__post_init__` runs, and
224
+ `init=False` fields get their default. The fields are set as the generated
225
+ `__init__` sets them: an `__init__` of your own is not called. A `TypedDict` becomes a `dict` with
226
+ its keys only. A value of the wrong type raises
227
+ `fastsimdjson.ValidationError` (a `ValueError`) with its path:
228
+
229
+ ```
230
+ ValidationError: Expected `int`, got `str` - at `$.owner.id`
231
+ ```
232
+
233
+ A `ValueError` or `TypeError` raised by `__post_init__` becomes a
234
+ `ValidationError` too, with the path. Invalid JSON raises
235
+ `JSONDecodeError`, and the documents that only `json` accepts (`NaN`, a
236
+ number that overflows a double) are converted the same way, from what
237
+ `json` returns; past what Python's stack allows, those raise
238
+ `RecursionError`, as `json` does. A set of values that cannot be hashed
239
+ (`set[list[int]]`) or a union that contains itself is a `TypeError`. The
240
+ description of each type is computed once and cached (the cache starts over
241
+ past 1024 types, so that types made on the fly do not pile up). `load`,
242
+ `load_file`, `loads_many` and `map_many` accept `type=` too; a
243
+ `ValidationError` ends the iteration of `loads_many`, as any error does. With
244
+ `threads=N` on free-threaded Python, the instances are built on N threads
245
+ (not with `fields=` or `lazy=True`).
246
+
150
247
  ### `dumps` and `dump`: like `json.dumps`
151
248
 
152
249
  ```python
@@ -194,6 +291,20 @@ serialize dataclasses, `datetime`, `date`, `time`, `UUID`, numpy arrays or
194
291
  `OPT_PASSTHROUGH_DATACLASS` and `OPT_PASSTHROUGH_DATETIME` were set, and the
195
292
  options that concern only these types are accepted and have no effect.
196
293
 
294
+ ### `minify`: strip whitespace without parsing
295
+
296
+ ```python
297
+ fastsimdjson.minify(b'{ "a" : [1, 2] }') # b'{"a":[1,2]}'
298
+ ```
299
+
300
+ `minify(data)` removes insignificant whitespace (spaces, tabs, newlines and
301
+ carriage returns outside of strings) and returns `bytes`. It accepts `bytes`,
302
+ `bytearray`, `memoryview` and `str`. It does not parse the document and does
303
+ not validate it: numbers, escapes, duplicate keys and key order are left as
304
+ they are, and input that is not valid JSON is minified the same way. An
305
+ unterminated string raises `JSONDecodeError` (the minifier does not report
306
+ where the string started, so the position is 0). The call releases the GIL.
307
+
197
308
  ### `dumpb_many`: NDJSON, on several threads
198
309
 
199
310
  ```python
@@ -252,6 +363,18 @@ separated:
252
363
  | `"comma"` | documents separated by commas: `{...}, {...}` (simdjson also accepts white space between them) |
253
364
  | `"array"` | the elements of one array: `[{...}, {...}]` |
254
365
 
366
+ To read a file without copying it, map it in memory:
367
+
368
+ ```python
369
+ import mmap
370
+ with open("log.ndjson", "rb") as f, mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as m:
371
+ names = fastsimdjson.map_many(fn, memoryview(m), threads=64)
372
+ ```
373
+
374
+ A `memoryview` of `bytes`, or of a file mapped with `mmap.ACCESS_READ` (as
375
+ here), is read in place, and the mapped file must not change meanwhile;
376
+ other buffers (a `bytearray`, a view of a writable mmap) are copied first.
377
+
255
378
  simdjson parses the input in batches (`batch_size`, 1 MB by default); a
256
379
  larger document is handled automatically. In every format, documents that
257
380
  simdjson rejects are handled as in `loads`: a document that `json` accepts is
@@ -276,9 +399,11 @@ documents instead of an iterator. `map_many(fn, data, **kw)` returns
276
399
  `[fn(doc) for doc in loads_many(data, **kw)]` (`parse_many` with
277
400
  `lazy=True`), with `fn` called in the threads. `threads=0` (or `None`) uses
278
401
  one thread per processor; small inputs use fewer threads (about one per
279
- 512 KB). The input is cut into chunks at newlines (before each `\x1e` for
280
- `json_seq`), so `threads` works with the formats `"whitespace"`, `"lines"`
281
- and `"json_seq"`.
402
+ 512 KB). The workers share one counter. Each claims the next 256 KB and
403
+ moves both ends forward to a newline (to the next `\x1e` for `json_seq`);
404
+ the pieces are adjacent. On `lines` and `json_seq` a document is never cut,
405
+ and one longer than 256 KB is parsed with the piece that started before it.
406
+ `threads` works with the formats `"whitespace"`, `"lines"` and `"json_seq"`.
282
407
 
283
408
  The results, and the exceptions, are those of one thread: when a chunk
284
409
  contains an error or a document that only `json` accepts, the documents
@@ -295,6 +420,19 @@ document, and the Python objects of all of them, to the calling thread.
295
420
  With the GIL (the default build of Python), the calling thread does all the
296
421
  work: `threads` has no effect on speed.
297
422
 
423
+ With `drop_none=True`, `map_many` leaves out the results that are `None`:
424
+ when `fn` keeps only a few documents, the threads do not build a list
425
+ entry for each of the others, and the calling thread has fewer to collect.
426
+
427
+ ```python
428
+ def starred(event):
429
+ kind, repo = event
430
+ return repo if kind == "WatchEvent" else None
431
+
432
+ names = fastsimdjson.map_many(starred, data, threads=64, drop_none=True,
433
+ fields=["/type", "/repo/name"])
434
+ ```
435
+
298
436
  ### Only some fields: `fields=`
299
437
 
300
438
  When you need a few values from each document, `fields` extracts them
@@ -322,9 +460,22 @@ missing key, an index past the end, or a step into a scalar) gives
322
460
  As with `at_pointer`, a key that appears twice in an object refers to its
323
461
  first occurrence. `fields` cannot be combined with `lazy=True`.
324
462
 
325
- On 7.6 GB of GitHub events, `map_many` with three fields ran at 2.8 GB/s on
326
- one core of an Intel Xeon Gold 6548N, against 2.2 GB/s with lazy views
327
- (`lazy=True`). With 64 threads, it ran at 78 GB/s (lazy views: 61 GB/s).
463
+ With the formats `"whitespace"` and `"lines"`, `fields` reads the documents
464
+ with simdjson's On-Demand API: the top level of each document, the keys on
465
+ the way to the pointers and the values found there are read and validated,
466
+ so a malformed or incomplete document is still an error. The values that no
467
+ pointer reaches are skipped without being checked, so an invalid value
468
+ elsewhere in a document (`{"a": 1, "b": tru}` with `fields="/a"`) goes
469
+ unnoticed. A value that is read is handled as without `fields`: an error
470
+ raises `JSONDecodeError`, and a document that only `json` accepts is decoded
471
+ by `json`. The whole documents are parsed (and validated) with the other
472
+ formats, and when a pointer is `""` or leads into the value of another
473
+ pointer (`["/a", "/a/b"]`).
474
+
475
+ On 7.6 GB of GitHub events, `map_many` with three fields ran at 2.2 GB/s on
476
+ one core of an Intel Xeon Gold 6548N, against 1.8 GB/s with lazy views
477
+ (`lazy=True`). With 64 threads (free-threaded Python 3.14.10t), it ran at
478
+ 84 GB/s (lazy views: 76 GB/s).
328
479
 
329
480
  ### Arrow: `loads_arrow`, `load_arrow_file` and `dumpb_arrow`
330
481
 
@@ -354,7 +505,7 @@ once the batches are taken). fastsimdjson does not depend on pyarrow.
354
505
 
355
506
  * The schema is a `pyarrow.Schema` (or any object with `__arrow_c_schema__`)
356
507
  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
508
+ doubles, strings, timestamps, structs and lists of these, or null. A field absent from a
358
509
  record is null; a key absent from the schema is skipped, or an error with
359
510
  `error_on_unknown_fields=True`. Skipped values are checked to be valid
360
511
  JSON, unless `validate_skipped=False` (then only their structure is).
@@ -365,6 +516,19 @@ once the batches are taken). fastsimdjson does not depend on pyarrow.
365
516
  type of its other values and integers become doubles next to other
366
517
  numbers; other mixes of types raise `ValueError`. Strings stay strings (no
367
518
  timestamps).
519
+ * A timestamp field (`pa.timestamp("us", tz="UTC")`, any unit, with or
520
+ without a time zone) reads ISO 8601 strings, such as the `created_at` of
521
+ GH Archive events (`"2015-01-01T15:00:00Z"`): a date (a four-digit year), then optionally a
522
+ time (`T` or a space, then `15`, `15:00`, `15:00:00` or
523
+ `15:00:00.123456`), then optionally `Z` or an offset (`+05:00`). A time
524
+ without `Z` or an offset is UTC. An integer is a count of units since 1970.
525
+ As with `pyarrow.json.read_json` (which returns the same table from the
526
+ strings it accepts; a lowercase `t` or `z` and a comma before the fraction
527
+ are accepted here too), a fraction
528
+ with more digits than the unit raises `ValueError`, as does an invalid
529
+ date. Reading the timestamps costs next to nothing: GH Archive with
530
+ `created_at` as `timestamp[us, UTC]` reads at 2.11 GB/s on one core, as
531
+ with strings, against 0.45 GB/s for pyarrow and 0.21 GB/s for polars.
368
532
  * A new batch starts every `block_size` bytes of input. With `threads=N`
369
533
  (`threads=0` or `None`: one per processor), N threads read blocks of
370
534
  `block_size` bytes, cut at line ends: a record must then fit on one line.
@@ -378,11 +542,17 @@ NDJSON `bytes`, one object per row: a `pyarrow.Table`, `RecordBatch`,
378
542
  relation, an `ArrowStream`, or any object with `__arrow_c_stream__` or
379
543
  `__arrow_c_array__`. It writes integers of 8 to 64 bits, floats and doubles
380
544
  (as `dumpb` writes them, NaN and infinities as `null`), booleans, strings
381
- (including large strings and string views), structs and lists (including
382
- large and fixed-size lists); other types raise `ValueError`. With
545
+ (including large strings and string views), timestamps (ISO 8601 in UTC,
546
+ `"2015-01-01T15:00:00.250000Z"`, with `Z` when the timestamp has a time zone
547
+ and the fraction when it is not zero), dates (`"2015-01-01"`), structs and
548
+ lists (including large and fixed-size lists); other types raise
549
+ `ValueError`. With
383
550
  `write_nulls=False`, null fields are omitted. With `threads=N`, N threads
384
551
  write ranges of rows into the result. The output reads back with
385
- `loads_arrow`, and with `loads_many(data, format="lines")`.
552
+ `loads_arrow`, and with `loads_many(data, format="lines")`, except for
553
+ timestamps and dates outside the years 0000 to 9999: their year is written
554
+ with more digits or a minus sign, which `loads_arrow` does not read (nor
555
+ does pyarrow).
386
556
 
387
557
  These functions release the GIL and run their threads outside Python, with
388
558
  or without free threading. They are built on
@@ -449,18 +619,25 @@ could be changed by another thread while we read it, so it is copied first:
449
619
  always by `loads_many`, `parse_many` and `map_many` (the iterator outlives
450
620
  the call) and by `loads_arrow`, `json_to_msgpack` and `msgpack_to_json`
451
621
  (which release the GIL), and only on a free-threaded build by `loads` and
452
- `parse`. Likewise, on a free-threaded build, `dumps` and `dumpb` hold
622
+ `parse`. The exception: `loads_many`, `parse_many` and `map_many` read a
623
+ read-only, contiguous `memoryview` of `bytes`, or of a file mapped with
624
+ `mmap.ACCESS_READ`, in place (the file must not change meanwhile). Other
625
+ read-only views (`memoryview(bytearray).toreadonly()`, a read-only view of a
626
+ writable mmap) are copied, since what they show can still change. Likewise, on a free-threaded build, `dumps` and `dumpb` hold
453
627
  references to the items of the containers they serialize.
454
628
 
455
629
  ### `release`
456
630
 
457
631
  `release()` frees the simdjson parser and the string caches kept by the
458
- calling thread. Views returned by `parse` remain valid.
632
+ calling thread. On free-threaded Python, it also has the idle worker threads
633
+ of the parallel streams (`threads=N`) free theirs; a worker busy with a
634
+ stream of another thread does so when it is done. Views returned by `parse`
635
+ remain valid.
459
636
 
460
637
  ## Build and test
461
638
 
462
639
  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.4 (NDJSON to Arrow
640
+ 5.1.1 and simdutf 9.2.1 amalgamations, simdjson_arrow 0.1.5 (NDJSON to Arrow
464
641
  and back: `simdjson_arrow.h` and `simdjson_arrow.cpp`) and simdjson_msgpack
465
642
  0.1.1 (JSON to MessagePack and back: `simdjson_msgpack.h` and
466
643
  `simdjson_msgpack.cpp`), both under the Apache-2.0 license, are already in
@@ -516,7 +693,8 @@ order; `tests/test_lazy.py` checks the views returned by `parse` the same way,
516
693
  `tests/test_dumps.py` compares `dumps` with `json.dumps` and `dumpb` with
517
694
  orjson (output and exceptions; the orjson comparisons are skipped when orjson
518
695
  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. It
696
+ `tests/test_stream.py` and `tests/test_files.py` cover streams and files, and
697
+ `tests/test_minify.py` covers `minify`. The suite
520
698
  covers scalars, integers past 64 bits, UTF-8 strings at every length from 0 to
521
699
  199, the key cache, random documents, rejected input, deep
522
700
  nesting, padding at a page boundary, a saturated array count, reference
@@ -536,7 +714,8 @@ The benchmark scripts need simdjson-data and the `bench` extra (orjson,
536
714
  jiter, msgspec, pysimdjson, cysimdjson). `bench.py` times `loads` against
537
715
  `json.loads`, orjson and jiter, `bench_lazy.py` times `parse` against pysimdjson and
538
716
  cysimdjson, `bench_dumps.py` times `dumps` against `json.dumps` and `dumpb`
539
- against orjson and msgspec, and `bench_many.py` times `loads_many`.
717
+ against orjson and msgspec, `bench_many.py` times `loads_many`, and
718
+ `bench_minify.py` times `minify` against parsing and serializing again.
540
719
 
541
720
  pip:
542
721
 
@@ -546,6 +725,7 @@ python bench.py
546
725
  python bench_lazy.py
547
726
  python bench_dumps.py
548
727
  python bench_many.py
728
+ python bench_minify.py
549
729
  ```
550
730
 
551
731
  uv:
@@ -556,13 +736,15 @@ python bench.py
556
736
  python bench_lazy.py
557
737
  python bench_dumps.py
558
738
  python bench_many.py
739
+ python bench_minify.py
559
740
  ```
560
741
 
561
742
  ## Benchmarks
562
743
 
563
- Intel Xeon Gold 6548N (Emerald Rapids), one core, Python 3.14.6,
564
- fastsimdjson 0.3.0 (simdjson 5.0.2), the 22 files of
565
- [simdjson-data](https://github.com/simdjson/simdjson-data). The scripts are in
744
+ Intel Xeon Gold 6548N (Emerald Rapids), one core unless stated otherwise,
745
+ Python 3.14.10 (free-threaded Python 3.14.10t for the streams on several
746
+ threads), fastsimdjson 1.0.0 (simdjson 5.1.1) built with GCC 16.2, the 22
747
+ files of [simdjson-data](https://github.com/simdjson/simdjson-data). The scripts are in
566
748
  this repository and in
567
749
  [the blog repository](https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/tree/master/2026/09/pysimdjson).
568
750
 
@@ -573,32 +755,32 @@ geometric mean over the 22 files (higher is better).
573
755
 
574
756
  <picture>
575
757
  <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.78 GB/s, orjson 0.60, msgspec 0.53, jiter 0.48, 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">
758
+ <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
759
  </picture>
578
760
 
579
761
  | parser | GB/s | vs `json.loads` |
580
762
  |---|---:|---:|
581
763
  | json (standard library) | 0.22 | 1.00× |
582
- | simplejson 4.2.0 | 0.23 | 1.05× |
583
- | python-rapidjson 1.25 | 0.24 | 1.10× |
584
- | ujson 6.0.0 | 0.37 | 1.66× |
585
- | cysimdjson 26.27 | 0.43 | 1.96× |
586
- | pysimdjson 7.0.2 | 0.44 | 1.98× |
587
- | jiter 0.17.0 (no string cache) | 0.44 | 2.00× |
588
- | jiter 0.17.0 (string cache, the default) | 0.48 | 2.21× |
589
- | msgspec 0.22.0 | 0.53 | 2.42× |
590
- | orjson 3.12.0 | 0.60 | 2.74× |
591
- | **fastsimdjson `loads`** | **0.78** | **3.53×** |
592
-
593
- fastsimdjson is the fastest on 21 of the 22 files, and ties with orjson on
594
- `numbers.json`, an array of floating-point numbers (within 2%). On numbers,
595
- both spend most of their time creating Python floats, which costs the same in
596
- both: simdjson parses the numbers of these files 15% to 30% faster than
597
- orjson's parser (yyjson), but that is a small part of the total. Part of the
598
- gain comes from pausing the garbage collector while the objects are built.
599
- Timing each call on its own, fastsimdjson's lead over orjson is 1.33× with
600
- the collector enabled and 1.22× with it disabled (geometric means); without
601
- the collector, `canada.json`, `mesh.json` and `numbers.json` are ties. yyjson 4.0.6 is left out: it
764
+ | simplejson 4.3.0 | 0.23 | 1.04× |
765
+ | python-rapidjson 1.26 | 0.24 | 1.08× |
766
+ | ujson 6.1.0 | 0.37 | 1.64× |
767
+ | cysimdjson 26.27 | 0.43 | 1.95× |
768
+ | pysimdjson 8.0.0 | 0.44 | 1.97× |
769
+ | jiter 0.19.0 (no string cache) | 0.44 | 1.98× |
770
+ | msgspec 0.22.0 | 0.53 | 2.38× |
771
+ | jiter 0.19.0 (string cache, the default) | 0.54 | 2.43× |
772
+ | orjson 3.13.0 | 0.60 | 2.70× |
773
+ | **fastsimdjson `loads`** | **0.77** | **3.46×** |
774
+
775
+ fastsimdjson is the fastest on 21 of the 22 files. orjson is 12% faster on
776
+ `numbers.json`, an array of floating-point numbers. On numbers, both spend
777
+ most of their time creating Python floats, which costs the same in both:
778
+ simdjson parses the numbers of these files faster than orjson's parser
779
+ (yyjson), but that is a small part of the total. Part of the gain comes from
780
+ pausing the garbage collector while the objects are built. fastsimdjson's
781
+ lead over orjson is 1.28× with the collector enabled and 1.18× with it
782
+ disabled (geometric means); without the collector, orjson is also 3 to 4%
783
+ faster on `canada.json` and `mesh.json`. yyjson 4.0.6 is left out: it
602
784
  returns wrong strings for non-ASCII text. jiter (the parser of pydantic)
603
785
  caches strings by default; turning the cache off (`cache_mode=False`) makes it
604
786
  slower here.
@@ -616,34 +798,74 @@ and the screen name of the 100 statuses of `twitter.json`:
616
798
 
617
799
  <picture>
618
800
  <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 158 µs, pysimdjson 179, cysimdjson 229, msgspec 336, fastsimdjson loads 861, orjson 1009, jiter 1281, jiter without its string cache 1592, json 3922">
801
+ <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
802
  </picture>
621
803
 
622
804
  | method | µs |
623
805
  |---|---:|
624
- | `json.loads` | 3922 |
625
- | jiter (no string cache) | 1592 |
626
- | jiter (string cache) | 1281 |
627
- | orjson | 1009 |
628
- | fastsimdjson `loads` | 861 |
629
- | msgspec (typed `Struct`) | 336 |
630
- | cysimdjson (lazy) | 229 |
631
- | pysimdjson (lazy) | 179 |
632
- | **fastsimdjson `parse`** | **158** |
633
-
634
- Here `parse` is about 25 times faster than `json.loads` and 5.5 times faster
806
+ | `json.loads` | 3977 |
807
+ | jiter (no string cache) | 1602 |
808
+ | jiter (string cache) | 1156 |
809
+ | orjson | 971 |
810
+ | fastsimdjson `loads` | 844 |
811
+ | msgspec (typed `Struct`) | 337 |
812
+ | cysimdjson (lazy) | 235 |
813
+ | pysimdjson (lazy) | 169 |
814
+ | **fastsimdjson `parse`** | **156** |
815
+
816
+ Here `parse` is about 25 times faster than `json.loads` and 5.4 times faster
635
817
  than `loads`. Most of its time is the simdjson parse itself.
636
818
 
819
+ ### Typed decoding
820
+
821
+ `loads(data, type=T)` against msgspec (`msgspec.json.Decoder(T)` with the
822
+ same dataclasses, and with the equivalent `msgspec.Struct` classes), pydantic
823
+ (`TypeAdapter(...).validate_json`, with the equivalent models) and
824
+ `cattrs.structure(orjson.loads(data), T)`. Three cases:
825
+
826
+ * **twitter:** `twitter.json` as a dataclass of 100 statuses, six fields of
827
+ each status and four of its user, the rest skipped.
828
+ * **citm:** `citm_catalog.json` typed in full (dicts of dataclasses, lists of
829
+ nested dataclasses).
830
+ * **gh:** 64 MB of GH Archive events (NDJSON), six fields of each event
831
+ (`loads_many(data, type=T)`, one call per line for the others).
832
+
833
+ MB/s, one core of an Intel Xeon Gold 6548N, Python 3.14.10, best of 3 runs
834
+ of 7 (`python bench_typed.py simdjson-data/jsonexamples gharchive.ndjson`):
835
+
836
+ <picture>
837
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_typed_dark.png">
838
+ <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">
839
+ </picture>
840
+
841
+ | | twitter | citm | gh |
842
+ |---|---:|---:|---:|
843
+ | **fastsimdjson `loads(type=)`** | **2597** | **981** | **2055** |
844
+ | msgspec (Struct) | 1520 | 632 | 1296 |
845
+ | msgspec (dataclass) | 1428 | 467 | 1156 |
846
+ | pydantic 2.14 | 659 | 192 | 514 |
847
+ | orjson + cattrs | 553 | 187 | 420 |
848
+ | fastsimdjson `loads` (dicts, untyped) | 933 | 1074 | 431 |
849
+
850
+ fastsimdjson is 1.5 to 1.7 times as fast as msgspec with Structs, 1.8 to 2.1
851
+ times as fast with the same dataclasses, and 3.9 to 5.1 times as fast as
852
+ pydantic. When most of the document is not needed (twitter, gh), typed
853
+ decoding is also 2.8 to 4.8 times as fast as building the dicts.
854
+
855
+ On free-threaded Python 3.14.10t, `loads_many(data, type=T, threads=N)` read
856
+ the 886 MB GH Archive file into dataclasses at 1.82 GB/s on one thread,
857
+ 12.0 GB/s on 8 and 33.3 GB/s on 32.
858
+
637
859
  ### `dumps` against `json.dumps`
638
860
 
639
861
  <picture>
640
862
  <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.63 times faster than json.dumps">
863
+ <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
864
  </picture>
643
865
 
644
- `dumps` returns exactly the `str` of `json.dumps` and is 4.6 times faster
645
- (geometric mean over the 22 files; from 3.1 times on `citm_catalog.json` to
646
- 12 times on `numbers.json`).
866
+ `dumps` returns exactly the `str` of `json.dumps` and is 4.2 times faster
867
+ (geometric mean over the 22 files; from 2.7 times on `citm_catalog.json` to
868
+ 10.5 times on `canada.json`).
647
869
 
648
870
  ### `dumpb` against orjson and msgspec
649
871
 
@@ -651,43 +873,71 @@ than `loads`. Most of its time is the simdjson parse itself.
651
873
  `bytes`; `dumpb` and orjson produce identical bytes on every file. With the
652
874
  standard library, the same compact bytes come from
653
875
  `json.dumps(obj, separators=(",", ":"), ensure_ascii=False).encode()`.
654
- Microseconds:
876
+ Each call encodes a fresh copy of the document (`bench_dumps.py`), so no
877
+ encoder gains from what it cached on the objects at a previous call. One
878
+ core of an Intel Xeon Gold 6548N, Python 3.14.10, GCC 16.2, fastsimdjson
879
+ 1.0.0, orjson 3.13.0, msgspec 0.22.0. Microseconds:
655
880
 
656
881
  <picture>
657
882
  <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 10.09x, orjson 9.69x, msgspec 6.03x">
883
+ <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
884
  </picture>
660
885
 
661
886
  | file | `json.dumps(...).encode()` | fastsimdjson `dumpb` | orjson | msgspec |
662
887
  |---|---:|---:|---:|---:|
663
- | twitter | 1827 | 202 | 204 | 330 |
664
- | citm_catalog | 2921 | 432 | 432 | 499 |
665
- | github_events | 177 | 17 | 19 | 31 |
666
- | gsoc-2018 | 15386 | 595 | 554 | 1462 |
667
- | update-center | 2482 | 254 | 232 | 477 |
668
- | canada | 38101 | 2432 | 2936 | 3640 |
669
- | mesh | 8726 | 785 | 999 | 1370 |
670
- | numbers | 2530 | 178 | 200 | 332 |
671
-
672
- `dumpb` and orjson are on par: over the 22 files, `dumpb` is 4% faster
673
- (geometric mean), from 10% slower on text-heavy or tiny files
674
- (`gsoc-2018.json`, `update-center.json`, `repeat.json`) to 27% faster on files
675
- full of numbers. Both are 1.7
676
- times faster than msgspec and 10 times faster than `json`. The comparison was
677
- run on a processor with AVX-512, which `dumpb` and orjson both use to escape
678
- strings; other x64 processors use SSE2 and ARM processors NEON.
888
+ | twitter | 1804 | 258 | 313 | 387 |
889
+ | citm_catalog | 3114 | 651 | 666 | 716 |
890
+ | github_events | 211 | 21 | 20 | 32 |
891
+ | gsoc-2018 | 12153 | 956 | 1165 | 2095 |
892
+ | update-center | 2647 | 309 | 298 | 514 |
893
+ | canada | 37821 | 2743 | 2480 | 3978 |
894
+ | mesh | 8903 | 876 | 1049 | 1401 |
895
+ | numbers | 2473 | 201 | 204 | 332 |
896
+
897
+ Over the 22 files, `dumpb` is 8% faster than orjson (geometric mean), from
898
+ 10% slower on `canada.json` (mostly floating-point numbers) and up to 6%
899
+ slower on the smallest files (`twitter_api_response.json`,
900
+ `github_events.json`) to 22% faster on `gsoc-2018.json`, whose strings are
901
+ mostly not ASCII, and 35% faster on `semanticscholar-corpus.json`. `dumpb` is
902
+ 1.5 times faster than msgspec (orjson 1.4 times) and 8 times faster than
903
+ `json`. The comparison was run on a processor
904
+ with AVX-512, which `dumpb` and orjson both use to escape strings; other x64
905
+ processors use SSE2 and ARM processors NEON.
906
+
907
+ ### `minify`
908
+
909
+ `minify` only removes whitespace. The other columns parse the document and
910
+ serialize it again, which also validates it and rewrites numbers. Geometric
911
+ mean over the 22 files, one core of an Intel Xeon Gold 6548N, Python 3.14.10,
912
+ GCC 16.2, orjson 3.13.0 (`bench_minify.py`):
913
+
914
+ <picture>
915
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_minify_dark.png">
916
+ <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">
917
+ </picture>
918
+
919
+ | method | GB/s |
920
+ |---|---:|
921
+ | **fastsimdjson `minify`** | **18.64** |
922
+ | `loads` + `dumpb` | 0.54 |
923
+ | orjson `loads` + `dumps` | 0.44 |
924
+ | `json.loads` + `json.dumps` | 0.11 |
925
+
926
+ Per file, `minify` runs from 15.4 GB/s (`canada.json`) to 20.7 GB/s
927
+ (`apache_builds.json`).
679
928
 
680
929
  ### Writing NDJSON with `dumpb_many`
681
930
 
682
931
  The 593,945 events of two hours of [GH Archive](https://www.gharchive.org/)
683
932
  (1.87 GB of NDJSON), written back as NDJSON from Python objects. With the
684
- GIL (Python 3.14.6), one thread: `orjson.dumps` on each record, joined, runs
685
- at 0.94 GB/s, `dumpb` on each record at 1.07 GB/s, and `dumpb_many` at
686
- 1.41 GB/s. On free-threaded Python 3.14.6t, GB/s:
933
+ GIL (Python 3.14.10), one thread: `orjson.dumps` on each record, joined, runs
934
+ at 0.93 GB/s, `dumpb` on each record at 0.93 GB/s, and `dumpb_many` at
935
+ 1.49 GB/s. On free-threaded Python 3.14.10t, GB/s (up to 32 threads on the
936
+ cores of one socket, 64 on both):
687
937
 
688
938
  | threads | 1 | 8 | 32 | 64 |
689
939
  |---|---:|---:|---:|---:|
690
- | `dumpb_many(records, threads=N)` | 1.3 | 6.0 | 11 | 12 |
940
+ | `dumpb_many(records, threads=N)` | 1.48 | 5.6 | 11.6 | 10.5 |
691
941
 
692
942
  ### NDJSON to Arrow and back
693
943
 
@@ -697,52 +947,52 @@ structs; the rest of each event is skipped), or inferring the schema. Reading
697
947
  gives a `pyarrow.Table` (`pyarrow.table(fastsimdjson.loads_arrow(data,
698
948
  schema, threads=N))`); the time includes the import into pyarrow. Writing
699
949
  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, DuckDB
701
- 2.0, fastsimdjson 0.10.1 (the manylinux wheel), Intel Xeon Gold 6548N (up to
702
- 32 threads on the 32 cores of one socket; 64 threads on both sockets).
950
+ DuckDB `COPY ... TO` (on tmpfs). Python 3.14.10, pyarrow 26.0, polars 2.1,
951
+ DuckDB 2.0, fastsimdjson 1.0.0, Intel Xeon Gold 6548N (up to 32 threads on
952
+ the 32 cores of one socket; 64 threads on both sockets).
703
953
 
704
954
  <picture>
705
955
  <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.75 GB/s, pyarrow 0.18, polars 0.27; GH Archive, fastsimdjson 2.08, pyarrow 0.46, polars 0.55; flat with an inferred schema, fastsimdjson 0.77, pyarrow 0.18, polars 0.09">
956
+ <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
957
  </picture>
708
958
 
709
959
  <picture>
710
960
  <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 14.7 GB/s, pyarrow 5.3, polars 4.3; GH Archive, fastsimdjson 29.7, pyarrow 12.3, polars 4.0; flat with an inferred schema, fastsimdjson 16.0, pyarrow 5.0, polars 0.12">
961
+ <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
962
  </picture>
713
963
 
714
964
  <picture>
715
965
  <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.90 GB/s, polars 0.45, DuckDB 0.30; GH Archive, fastsimdjson 1.09, polars 0.46, DuckDB 0.31">
966
+ <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
967
  </picture>
718
968
 
719
969
  <picture>
720
970
  <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 10.3 GB/s, polars 1.6, DuckDB 3.0; GH Archive, fastsimdjson 4.5, polars 1.1, DuckDB 0.82">
971
+ <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
972
  </picture>
723
973
 
724
974
  All the numbers, in GB/s:
725
975
 
726
976
  | | threads | 1 | 8 | 32 | 64 |
727
977
  |---|---|---:|---:|---:|---:|
728
- | flat, read | fastsimdjson `loads_arrow` | **0.75** | **5.6** | **14.7** | **17.9** |
729
- | | pyarrow `read_json` | 0.18 | 1.4 | 5.3 | 7.9 |
730
- | | polars `read_ndjson` | 0.27 | 2.0 | 4.3 | 3.2 |
731
- | flat, read, inferring the schema | fastsimdjson `loads_arrow` | **0.77** | **5.7** | **16.0** | **16.9** |
732
- | | pyarrow `read_json` | 0.18 | 1.4 | 5.0 | 6.7 |
978
+ | flat, read | fastsimdjson `loads_arrow` | **0.76** | **5.7** | **15.0** | **18.0** |
979
+ | | pyarrow `read_json` | 0.18 | 1.4 | 5.3 | 7.8 |
980
+ | | polars `read_ndjson` | 0.27 | 2.0 | 4.3 | 3.1 |
981
+ | flat, read, inferring the schema | fastsimdjson `loads_arrow` | **0.79** | **5.6** | **14.4** | **12.5** |
982
+ | | pyarrow `read_json` | 0.18 | 1.4 | 5.0 | 6.8 |
733
983
  | | polars `read_ndjson` | 0.09 | 0.12 | 0.12 | 0.12 |
734
- | GH Archive, read | fastsimdjson `loads_arrow` | **2.08** | **13.8** | **29.7** | **25.8** |
735
- | | pyarrow `read_json` | 0.46 | 3.5 | 12.3 | 16.0 |
736
- | | polars `read_ndjson` | 0.55 | 3.7 | 4.0 | 3.2 |
737
- | flat, write | fastsimdjson `dumpb_arrow` | **0.90** | **3.6** | **10.3** | **13.8** |
738
- | | polars | 0.45 | 1.5 | 1.6 | 1.5 |
739
- | | DuckDB | 0.30 | 2.0 | 3.0 | 2.4 |
740
- | GH Archive, write | fastsimdjson `dumpb_arrow` | **1.09** | **3.1** | **4.5** | **4.5** |
741
- | | polars | 0.46 | 1.1 | 1.1 | 0.99 |
742
- | | DuckDB | 0.31 | 1.7 | 0.82 | 0.83 |
743
-
744
- `load_arrow_file` on the same files, from the page cache, reads at 0.68 and
745
- 1.5 GB/s on one thread, 9.0 and 13.6 GB/s on 32 threads. The benchmark is
984
+ | GH Archive, read | fastsimdjson `loads_arrow` | **1.96** | **12.9** | **27.5** | **24.3** |
985
+ | | pyarrow `read_json` | 0.46 | 3.5 | 12.1 | 14.5 |
986
+ | | polars `read_ndjson` | 0.54 | 3.5 | 4.0 | 3.1 |
987
+ | flat, write | fastsimdjson `dumpb_arrow` | **0.92** | **3.7** | **9.6** | **12.1** |
988
+ | | polars | 0.45 | 1.1 | 1.6 | 1.5 |
989
+ | | DuckDB | 0.32 | 2.3 | 4.8 | 3.4 |
990
+ | GH Archive, write | fastsimdjson `dumpb_arrow` | **1.08** | **3.0** | **4.8** | **4.2** |
991
+ | | polars | 0.46 | 0.52 | 0.86 | 1.06 |
992
+ | | DuckDB | 0.32 | 1.3 | 1.1 | 0.86 |
993
+
994
+ `load_arrow_file` on the same files, from the page cache, reads at 0.69 and
995
+ 1.5 GB/s on one thread, 9.1 and 13.0 GB/s on 32 threads. The benchmark is
746
996
  `THREADS=N python bench_arrow.py flat.ndjson:flat gharchive.ndjson:gh
747
997
  flat.ndjson:infer`; `path:infer` times any NDJSON file without a schema. The
748
998
  flat file comes from
@@ -758,17 +1008,17 @@ Python, which decode into Python objects, then encode them:
758
1008
  `ormsgpack.packb(orjson.loads(s))`, `msgspec.msgpack.encode(msgspec.json.decode(s))`
759
1009
  and so on. The 22 files of simdjson-data, geometric means of the speeds, in
760
1010
  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 6338 (Ice Lake), one core.
1011
+ Python 3.14.10, msgpack 1.2, orjson 3.13, ormsgpack 1.13, msgspec 0.22, Intel
1012
+ Xeon Gold 6548N, one core.
763
1013
 
764
1014
  <picture>
765
1015
  <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.37 GB/s, orjson with ormsgpack 0.35, msgspec 0.34, fastsimdjson loads with msgpack 0.28, orjson with msgpack 0.25, json with msgpack 0.13">
1016
+ <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
1017
  </picture>
768
1018
 
769
1019
  <picture>
770
1020
  <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 0.94 GB/s, ormsgpack with orjson 0.27, msgspec 0.25, msgpack with orjson 0.20, msgpack with fastsimdjson dumpb 0.20, msgpack with json 0.07">
1021
+ <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
1022
  </picture>
773
1023
 
774
1024
  Streams: the 304,929 events of an hour of GH Archive (886 MB of NDJSON), with
@@ -780,13 +1030,13 @@ sockets):
780
1030
 
781
1031
  <picture>
782
1032
  <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 15.0 GB/s on 64 threads, 10.8 on 32, 6.8 on 8, 1.18 on one thread, orjson with ormsgpack 0.29 on one thread; MessagePack to NDJSON: fastsimdjson 5.0 GB/s on 8 threads, 1.05 on one thread, msgpack with orjson 0.20">
1033
+ <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
1034
  </picture>
785
1035
 
786
1036
  | threads | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
787
1037
  |---|---:|---:|---:|---:|---:|---:|---:|
788
- | NDJSON to MessagePack | 1.18 | 1.88 | 4.2 | 6.8 | 8.6 | 10.8 | 15.0 |
789
- | MessagePack to NDJSON | 1.05 | 1.67 | 3.3 | 5.0 | 3.4 | 4.2 | 3.5 |
1038
+ | NDJSON to MessagePack | 1.31 | 2.45 | 4.7 | 8.7 | 14.0 | 16.0 | 22.7 |
1039
+ | MessagePack to NDJSON | 1.51 | 2.26 | 4.4 | 6.0 | 6.0 | 6.0 | 5.9 |
790
1040
 
791
1041
  MessagePack to NDJSON stops scaling at about eight threads: one thread must
792
1042
  find where the values end (MessagePack has no line ends) before the others
@@ -802,40 +1052,40 @@ files; best of three runs:
802
1052
 
803
1053
  <picture>
804
1054
  <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 0.94 GB/s, loads_many 0.38, msgspec decode_lines 0.37, fastsimdjson loads per line 0.33, msgspec decode per line 0.27, orjson per line 0.26, jiter per line 0.22, jiter without its string cache per line 0.20, json per line 0.12">
1055
+ <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
1056
  </picture>
807
1057
 
808
1058
  | method | ms | GB/s |
809
1059
  |---|---:|---:|
810
- | `json.loads` on each line | 169 | 0.12 |
811
- | jiter on each line (no string cache) | 98 | 0.20 |
812
- | jiter on each line (string cache) | 90 | 0.22 |
813
- | orjson on each line | 77 | 0.26 |
814
- | msgspec `decode` on each line | 74 | 0.27 |
815
- | fastsimdjson `loads` on each line | 60 | 0.33 |
816
- | msgspec `decode_lines` | 53 | 0.37 |
817
- | fastsimdjson `loads_many` | 52 | 0.38 |
818
- | fastsimdjson `parse_many` (views only) | 21 | 0.94 |
819
-
820
- msgspec's `decode_lines` and `loads_many` are on par (`loads_many` is about 2%
821
- faster). `parse_many` only creates the views; reading values from them adds to
1060
+ | `json.loads` on each line | 164 | 0.12 |
1061
+ | jiter on each line (no string cache) | 94 | 0.21 |
1062
+ | jiter on each line (string cache) | 84 | 0.23 |
1063
+ | msgspec `decode` on each line | 75 | 0.26 |
1064
+ | orjson on each line | 74 | 0.26 |
1065
+ | fastsimdjson `loads` on each line | 58 | 0.34 |
1066
+ | msgspec `decode_lines` | 55 | 0.36 |
1067
+ | fastsimdjson `loads_many` | 49 | 0.40 |
1068
+ | fastsimdjson `parse_many` (views only) | 17 | 1.13 |
1069
+
1070
+ `loads_many` is 13% faster than msgspec's `decode_lines`. `parse_many` only creates the views; reading values from them adds to
822
1071
  its time.
823
1072
 
824
1073
  ### Streams on several threads
825
1074
 
826
1075
  300 MB of NDJSON (146,624 records: tweets, GitHub events, citm performances,
827
- gsoc and update-center entries), free-threaded Python 3.14.6, collector
1076
+ gsoc and update-center entries), free-threaded Python 3.14.10t, collector
828
1077
  disabled (see below), Intel Xeon Gold 6548N (64 cores); GB/s:
829
1078
 
830
1079
  | threads | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
831
1080
  |---|---:|---:|---:|---:|---:|---:|---:|
832
- | `map_many(len, data, threads=N)` | 1.03 | 1.78 | 3.66 | 6.82 | 13.0 | 23.7 | **28.8** |
833
- | `parse_many(data, threads=N)` | 2.00 | 2.84 | 5.28 | 9.26 | 16.1 | 22.7 | 25.8 |
834
- | `loads_many(data, threads=N)` | 0.90 | 1.44 | 2.79 | 4.99 | 8.98 | 13.3 | 15.4 |
835
-
836
- `map_many` is 28 times faster on 64 threads than on one (up to 38 GB/s when
837
- nothing else runs in the process). `loads_many` builds every document for
838
- the calling thread and is 17 times faster. With the collector enabled,
1081
+ | `map_many(len, data, threads=N)` | 0.90 | 1.64 | 2.08 | 3.53 | 5.85 | 8.70 | 16.8 |
1082
+ | `parse_many(data, threads=N)` | 1.59 | 2.78 | 3.75 | 4.79 | 9.01 | 13.5 | **20.6** |
1083
+ | `loads_many(data, threads=N)` | 0.77 | 1.52 | 2.29 | 4.08 | 6.87 | 9.99 | 11.8 |
1084
+
1085
+ `map_many` is 19 times faster on 64 threads than on one, and `parse_many` 13
1086
+ times. `loads_many` builds every document for the calling thread and is 15
1087
+ times faster. On 64 threads, these numbers vary by up to a third from one
1088
+ run to the next. With the collector enabled,
839
1089
  Python collects after the call returns: it examines the millions of objects
840
1090
  just created, which takes about 0.1 s here, with or without threads.
841
1091
 
@@ -843,7 +1093,17 @@ just created, which takes about 0.1 s here, with or without threads.
843
1093
 
844
1094
  * The simdjson parser and the key and string caches are thread-local.
845
1095
  `release()` frees the parser and the cached strings retained by the calling
846
- thread, and they are freed when a Python thread exits. A parser that grows
847
- past 64 MB is freed on its own at the end of that call; its caches stay.
1096
+ thread and by the worker threads of the parallel streams, and they are
1097
+ freed when a Python thread exits. A parser that grows past 64 MB is freed
1098
+ on its own at the end of that call; its caches stay.
1099
+ * On free-threaded Python, the worker threads of the parallel streams
1100
+ (`threads=N`) are started at the first call that needs them and kept until
1101
+ the interpreter exits: starting threads costs about as much as the parsing.
1102
+ Idle workers wait without using the processor. Each one keeps a parser
1103
+ (about a megabyte) and its caches until `release()`. Free-threaded CPython
1104
+ also keeps the memory of freed objects for reuse, in the thread that
1105
+ allocated it, rather than returning it to the system (the standard `json`
1106
+ module shows the same): after a large threaded call, the process stays
1107
+ larger, and the next calls reuse that memory.
848
1108
  * Subinterpreters are not supported: the module keeps per-process state (its
849
1109
  types, and per-thread parsers and string caches).