fastsimdjson 0.9.0__tar.gz → 0.10.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 (34) hide show
  1. fastsimdjson-0.10.0/MANIFEST.in +2 -0
  2. {fastsimdjson-0.9.0/src/fastsimdjson.egg-info → fastsimdjson-0.10.0}/PKG-INFO +258 -13
  3. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/README.md +250 -12
  4. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/pyproject.toml +5 -4
  5. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/setup.py +9 -12
  6. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/src/fastsimdjson.cpp +811 -3
  7. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0/src/fastsimdjson.egg-info}/PKG-INFO +258 -13
  8. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/src/fastsimdjson.egg-info/SOURCES.txt +8 -1
  9. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/src/fastsimdjson.egg-info/requires.txt +6 -0
  10. fastsimdjson-0.10.0/tests/test_arrow.py +223 -0
  11. fastsimdjson-0.10.0/tests/test_msgpack.py +165 -0
  12. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/vendor/simdjson.cpp +181 -73
  13. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/vendor/simdjson.h +1335 -5693
  14. fastsimdjson-0.10.0/vendor/simdjson_arrow-LICENSE +201 -0
  15. fastsimdjson-0.10.0/vendor/simdjson_arrow.cpp +5169 -0
  16. fastsimdjson-0.10.0/vendor/simdjson_arrow.h +251 -0
  17. fastsimdjson-0.10.0/vendor/simdjson_msgpack-LICENSE +201 -0
  18. fastsimdjson-0.10.0/vendor/simdjson_msgpack.cpp +4955 -0
  19. fastsimdjson-0.10.0/vendor/simdjson_msgpack.h +206 -0
  20. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/vendor/zmij.h +8 -6
  21. fastsimdjson-0.9.0/MANIFEST.in +0 -2
  22. fastsimdjson-0.9.0/vendor/zmij.cc +0 -2263
  23. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/setup.cfg +0 -0
  24. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/src/fastsimdjson.egg-info/dependency_links.txt +0 -0
  25. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/src/fastsimdjson.egg-info/top_level.txt +0 -0
  26. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/tests/test_dumps.py +0 -0
  27. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/tests/test_files.py +0 -0
  28. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/tests/test_lazy.py +0 -0
  29. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/tests/test_loads.py +0 -0
  30. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/tests/test_stream.py +0 -0
  31. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/vendor/simdutf.cpp +0 -0
  32. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/vendor/simdutf.h +0 -0
  33. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/vendor/simdutf_c.h +0 -0
  34. {fastsimdjson-0.9.0 → fastsimdjson-0.10.0}/vendor/zmij-LICENSE +0 -0
@@ -0,0 +1,2 @@
1
+ include vendor/*.h vendor/*.cpp vendor/zmij-LICENSE vendor/simdjson_arrow-LICENSE vendor/simdjson_msgpack-LICENSE src/*.cpp
2
+ recursive-include tests *.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastsimdjson
3
- Version: 0.9.0
3
+ Version: 0.10.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
@@ -17,18 +17,25 @@ Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: 3.13
19
19
  Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: 3.15
20
21
  Classifier: Programming Language :: Python :: Implementation :: CPython
21
22
  Classifier: Topic :: Software Development :: Libraries
22
23
  Requires-Python: >=3.10
23
24
  Description-Content-Type: text/markdown
24
25
  Provides-Extra: test
25
26
  Requires-Dist: pytest; extra == "test"
27
+ Requires-Dist: msgpack; extra == "test"
26
28
  Provides-Extra: bench
27
29
  Requires-Dist: orjson; extra == "bench"
28
30
  Requires-Dist: jiter; extra == "bench"
29
31
  Requires-Dist: msgspec; extra == "bench"
30
32
  Requires-Dist: pysimdjson; extra == "bench"
31
33
  Requires-Dist: cysimdjson; extra == "bench"
34
+ Requires-Dist: pyarrow; extra == "bench"
35
+ Requires-Dist: polars; extra == "bench"
36
+ Requires-Dist: duckdb; extra == "bench"
37
+ Requires-Dist: msgpack; extra == "bench"
38
+ Requires-Dist: ormsgpack; extra == "bench"
32
39
 
33
40
  # fastsimdjson
34
41
 
@@ -43,6 +50,11 @@ Lines), on many threads with free-threaded Python, and can extract only the
43
50
  fields you need from each document. It writes JSON in two ways: `dumps` returns the same `str` as
44
51
  `json.dumps`, and `dumpb` returns the same `bytes` as `orjson.dumps`, as fast
45
52
  as orjson; `dumpb_many` writes NDJSON, on many threads with free-threaded
53
+ Python. `loads_arrow` and `dumpb_arrow` convert NDJSON to Apache Arrow
54
+ tables and back, for pyarrow, polars or DuckDB, on many threads with any
55
+ Python. `json_to_msgpack` and `msgpack_to_json` convert JSON to
56
+ [MessagePack](https://msgpack.org/) and back without building Python objects,
57
+ 3 to 4 times as fast as orjson with ormsgpack, on many threads with any
46
58
  Python.
47
59
 
48
60
  With pip:
@@ -57,8 +69,8 @@ With uv:
57
69
  uv pip install fastsimdjson # in a uv project: uv add fastsimdjson
58
70
  ```
59
71
 
60
- Wheels are available for Linux, macOS and Windows, for Python 3.10 to 3.14,
61
- including free-threaded Python 3.14.
72
+ Wheels are available for Linux, macOS and Windows, for Python 3.10 to 3.15,
73
+ including free-threaded Python 3.14 and 3.15.
62
74
 
63
75
  ## Usage
64
76
 
@@ -291,6 +303,132 @@ On 7.6 GB of GitHub events, `map_many` with three fields ran at 2.8 GB/s on
291
303
  one core of an Intel Xeon Gold 6548N, against 2.2 GB/s with lazy views
292
304
  (`lazy=True`). With 64 threads, it ran at 78 GB/s (lazy views: 61 GB/s).
293
305
 
306
+ ### Arrow: `loads_arrow`, `load_arrow_file` and `dumpb_arrow`
307
+
308
+ ```python
309
+ import pyarrow as pa
310
+ table = pa.table(fastsimdjson.loads_arrow(data)) # inferring the schema
311
+ schema = pa.schema([("id", pa.int64()), ("name", pa.string())])
312
+ table = pa.table(fastsimdjson.load_arrow_file("log.ndjson", schema, threads=8))
313
+ frame = polars.DataFrame(fastsimdjson.loads_arrow(data, schema))
314
+ data = fastsimdjson.dumpb_arrow(table) # b'{"id":1,"name":"x"}\n...'
315
+ data = fastsimdjson.dumpb_arrow(frame, threads=8) # a polars.DataFrame
316
+ ```
317
+
318
+ `loads_arrow(data, schema=None, *, block_size=1048576,
319
+ error_on_unknown_fields=False, validate_skipped=True, threads=None)` reads
320
+ NDJSON (one object per record) into Arrow record batches. The input is
321
+ `bytes`, `bytearray`, `memoryview` or `str`, read in place.
322
+ `load_arrow_file(path, ...)` maps the file in memory and reads it the same way
323
+ (the file must not shrink meanwhile). Both return a `fastsimdjson.ArrowStream`,
324
+ which goes to any library that supports the [Arrow PyCapsule
325
+ interface](https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html),
326
+ without a copy: `pyarrow.table(s)`, `pyarrow.RecordBatchReader.from_stream(s)`,
327
+ `polars.DataFrame(s)`, `duckdb.from_arrow(s)`... Like a `RecordBatchReader`,
328
+ it hands over its batches once (`ValueError` afterwards); `pyarrow.schema(s)`
329
+ gives its schema at any time, and `s.num_rows` the number of records (`None`
330
+ once the batches are taken). fastsimdjson does not depend on pyarrow.
331
+
332
+ * The schema is a `pyarrow.Schema` (or any object with `__arrow_c_schema__`)
333
+ whose fields are booleans, 64-bit integers, unsigned 64-bit integers,
334
+ doubles, strings, structs and lists of these, or null. A field absent from a
335
+ record is null; a key absent from the schema is skipped, or an error with
336
+ `error_on_unknown_fields=True`. Skipped values are checked to be valid
337
+ JSON, unless `validate_skipped=False` (then only their structure is).
338
+ * Without a schema, it is inferred as pyarrow's JSON reader does: `null`,
339
+ `true`/`false`, integers that fit in 64 bits (`int64`), other numbers
340
+ (`double`), strings, objects (structs, with the union of their fields in
341
+ order of first appearance) and arrays (lists). A field of nulls takes the
342
+ type of its other values and integers become doubles next to other
343
+ numbers; other mixes of types raise `ValueError`. Strings stay strings (no
344
+ timestamps).
345
+ * A new batch starts every `block_size` bytes of input. With `threads=N`
346
+ (`threads=0` or `None`: one per processor), N threads read blocks of
347
+ `block_size` bytes, cut at line ends: a record must then fit on one line.
348
+ When that fails, the input is read again on one thread, so that the errors
349
+ (`ValueError`, with the record number and the field) are the same with any
350
+ number of threads.
351
+
352
+ `dumpb_arrow(data, *, write_nulls=True, threads=None)` writes Arrow data as
353
+ NDJSON `bytes`, one object per row: a `pyarrow.Table`, `RecordBatch`,
354
+ `RecordBatchReader` or `StructArray`, a `polars.DataFrame`, a DuckDB
355
+ relation, an `ArrowStream`, or any object with `__arrow_c_stream__` or
356
+ `__arrow_c_array__`. It writes integers of 8 to 64 bits, floats and doubles
357
+ (as `dumpb` writes them, NaN and infinities as `null`), booleans, strings
358
+ (including large strings and string views), structs and lists (including
359
+ large and fixed-size lists); other types raise `ValueError`. With
360
+ `write_nulls=False`, null fields are omitted. With `threads=N`, N threads
361
+ write ranges of rows into the result. The output reads back with
362
+ `loads_arrow`, and with `loads_many(data, format="lines")`.
363
+
364
+ These functions release the GIL and run their threads outside Python, with
365
+ or without free threading. They are built on
366
+ [simdjson_arrow](https://github.com/simdjson/simdjson_arrow), a C++ library
367
+ (vendored).
368
+
369
+ ### MessagePack: `json_to_msgpack` and `msgpack_to_json`
370
+
371
+ ```python
372
+ packed = fastsimdjson.json_to_msgpack(b'{"id": 1, "tags": ["a", "b"], "score": 2.5}')
373
+ # b'\x83\xa2id\x01\xa4tags\x92\xa1a\xa1b\xa5score\xcb@\x04\x00\x00\x00\x00\x00\x00'
374
+ msgpack.unpackb(packed) # {'id': 1, 'tags': ['a', 'b'], 'score': 2.5}
375
+ fastsimdjson.msgpack_to_json(packed) # b'{"id":1,"tags":["a","b"],"score":2.5}'
376
+ stream = fastsimdjson.json_to_msgpack(ndjson, ndjson=True, threads=8) # one value per document
377
+ lines = fastsimdjson.msgpack_to_json(stream, stream=True, threads=8) # NDJSON again
378
+ ```
379
+
380
+ `json_to_msgpack(data, *, ndjson=False, block_size=1048576, threads=None)`
381
+ converts JSON (`bytes`, `bytearray`, `memoryview` or `str`, read in place) to
382
+ MessagePack `bytes` in the most compact encoding: the same bytes as
383
+ `msgpack.packb(json.loads(data))` (but for duplicate keys, which
384
+ `json.loads` drops, and integers beyond 64 bits). Integers take the smallest integer encoding
385
+ (integers beyond 64 bits become doubles), other numbers are doubles, and
386
+ strings, arrays and objects take the smallest header for their size; keys keep
387
+ their order, duplicates too. With `ndjson=True`, the input holds documents
388
+ separated by whitespace (NDJSON, JSON Lines), and each becomes one MessagePack
389
+ value, one after the other.
390
+
391
+ `msgpack_to_json(data, *, stream=False, validate_utf8=True,
392
+ binary_as_base64=True, ext_as_null=False, block_size=1048576, threads=None)`
393
+ converts MessagePack (any bytes-like object) to compact JSON `bytes`. Floats
394
+ get the shortest representation that gives them back, as Python's `repr`
395
+ (`1.0`, not `1`; `1e-05`; NaN and infinities as `null`), binary values as base64 strings, map keys that are not strings as
396
+ strings (`"1"`, `"true"`, `"null"`); extension values (timestamps too) raise
397
+ `ValueError`, or become `null` with `ext_as_null=True`. Strings must be valid
398
+ UTF-8 (unless `validate_utf8=False`). With `stream=True`, the input holds a
399
+ sequence of values (what `json_to_msgpack(..., ndjson=True)` or several
400
+ `msgpack.packb` calls give), and each becomes one line of NDJSON.
401
+
402
+ * Invalid input raises `ValueError`: `"TAPE_ERROR: ... (document 12)"` for
403
+ JSON, `"truncated string (byte 1234)"` for MessagePack.
404
+ * With `threads=N` (`threads=0` or `None`: one per processor), NDJSON and
405
+ streams are converted on N threads, in blocks of about `block_size` bytes.
406
+ A JSON document must then fit on one line; when that fails, the input is
407
+ converted again on one thread, so that errors are the same with any number
408
+ of threads. Single documents use one thread.
409
+ * The functions release the GIL and run their threads outside Python, with or
410
+ without free threading, and write their result straight into the `bytes`
411
+ object (no copy). No Python object is made from the data.
412
+
413
+ They are built on
414
+ [simdjson_msgpack](https://github.com/simdjson/simdjson_msgpack), a C++ library
415
+ (vendored).
416
+
417
+ ### Threads and free-threaded Python
418
+
419
+ The module is marked free-threading compatible (`Py_MOD_GIL_NOT_USED` on
420
+ Python 3.13 and newer), so importing it on a free-threaded build does not
421
+ re-enable the GIL. It is tested with many threads parsing, serializing and
422
+ sharing views and stream iterators on free-threaded Python 3.14 and 3.15.
423
+
424
+ `bytes` and `str` inputs are read in place. A `bytearray` or `memoryview`
425
+ could be changed by another thread while we read it, so it is copied first:
426
+ always by `loads_many`, `parse_many` and `map_many` (the iterator outlives
427
+ the call) and by `loads_arrow`, `json_to_msgpack` and `msgpack_to_json`
428
+ (which release the GIL), and only on a free-threaded build by `loads` and
429
+ `parse`. Likewise, on a free-threaded build, `dumps` and `dumpb` hold
430
+ references to the items of the containers they serialize.
431
+
294
432
  ### `release`
295
433
 
296
434
  `release()` frees the simdjson parser and the string caches kept by the
@@ -299,8 +437,15 @@ calling thread. Views returned by `parse` remain valid.
299
437
  ## Build and test
300
438
 
301
439
  Python 3.10 or newer, and a C++17 compiler (clang, GCC or MSVC). The simdjson
302
- 5.0.7 and simdutf 9.2.1 amalgamations, and zmij 1.2 (shortest float
303
- formatting, MIT license), are already in `vendor/`.
440
+ 5.1.1 and simdutf 9.2.1 amalgamations, simdjson_arrow 0.1.1 (NDJSON to Arrow
441
+ and back: `simdjson_arrow.h` and `simdjson_arrow.cpp`) and simdjson_msgpack
442
+ 0.1.1 (JSON to MessagePack and back: `simdjson_msgpack.h` and
443
+ `simdjson_msgpack.cpp`), both under the Apache-2.0 license, are already in
444
+ `vendor/`. simdjson_arrow includes zmij 1.2 (shortest float formatting, MIT
445
+ license), which simdjson_msgpack, `dumps` and `dumpb` also use
446
+ (`vendor/zmij.h`).
447
+ The tests of the Arrow functions (`tests/test_arrow.py`) run when pyarrow is
448
+ installed (and polars, for one of them); otherwise they are skipped.
304
449
 
305
450
  pip:
306
451
 
@@ -521,6 +666,112 @@ at 0.94 GB/s, `dumpb` on each record at 1.07 GB/s, and `dumpb_many` at
521
666
  |---|---:|---:|---:|---:|
522
667
  | `dumpb_many(records, threads=N)` | 1.3 | 6.0 | 11 | 12 |
523
668
 
669
+ ### NDJSON to Arrow and back
670
+
671
+ Two files: 4 million flat records (611 MB, 9 scalar fields), and 304,929 GH
672
+ Archive events (886 MB), read with a schema of 6 of their fields (two of them
673
+ structs; the rest of each event is skipped), or inferring the schema. Reading
674
+ gives a `pyarrow.Table` (`pyarrow.table(fastsimdjson.loads_arrow(data,
675
+ schema, threads=N))`); the time includes the import into pyarrow. Writing
676
+ starts from that table: fastsimdjson `dumpb_arrow`, polars `write_ndjson` and
677
+ DuckDB `COPY ... TO` (on tmpfs). Python 3.13, pyarrow 26.0, polars 2.1, DuckDB
678
+ 2.0, simdjson 5.1.0, Intel Xeon Gold 6548N (up to 32 threads on the 32 cores
679
+ of one socket; 64 threads on both sockets).
680
+
681
+ <picture>
682
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_1_dark.png">
683
+ <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.70 GB/s, pyarrow 0.18, polars 0.27; GH Archive, fastsimdjson 1.95, pyarrow 0.45, polars 0.53; flat with an inferred schema, fastsimdjson 0.72, pyarrow 0.17, polars 0.08">
684
+ </picture>
685
+
686
+ <picture>
687
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_32_dark.png">
688
+ <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 13.9 GB/s, pyarrow 5.1, polars 4.0; GH Archive, fastsimdjson 28.4, pyarrow 12.1, polars 3.8; flat with an inferred schema, fastsimdjson 13.3, pyarrow 4.8, polars 0.12">
689
+ </picture>
690
+
691
+ <picture>
692
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_1_dark.png">
693
+ <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.96 GB/s, polars 0.46, DuckDB 0.30; GH Archive, fastsimdjson 1.07, polars 0.47, DuckDB 0.31">
694
+ </picture>
695
+
696
+ <picture>
697
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_32_dark.png">
698
+ <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 7.8 GB/s, polars 1.3, DuckDB 2.8; GH Archive, fastsimdjson 4.7, polars 1.1, DuckDB 0.79">
699
+ </picture>
700
+
701
+ All the numbers, in GB/s:
702
+
703
+ | | threads | 1 | 8 | 32 | 64 |
704
+ |---|---|---:|---:|---:|---:|
705
+ | flat, read | fastsimdjson `loads_arrow` | **0.70** | **5.3** | **13.9** | **16.2** |
706
+ | | pyarrow `read_json` | 0.18 | 1.4 | 5.1 | 7.7 |
707
+ | | polars `read_ndjson` | 0.27 | 2.0 | 4.0 | 2.8 |
708
+ | flat, read, inferring the schema | fastsimdjson `loads_arrow` | **0.72** | **5.2** | **13.3** | **12.7** |
709
+ | | pyarrow `read_json` | 0.17 | 1.3 | 4.8 | 6.6 |
710
+ | | polars `read_ndjson` | 0.08 | 0.12 | 0.12 | 0.12 |
711
+ | GH Archive, read | fastsimdjson `loads_arrow` | **1.95** | **12.9** | **28.4** | **25.3** |
712
+ | | pyarrow `read_json` | 0.45 | 3.5 | 12.1 | 15.4 |
713
+ | | polars `read_ndjson` | 0.53 | 3.9 | 3.8 | 3.0 |
714
+ | flat, write | fastsimdjson `dumpb_arrow` | **0.96** | **3.9** | **7.8** | **12.6** |
715
+ | | polars | 0.46 | 1.1 | 1.3 | 1.6 |
716
+ | | DuckDB | 0.30 | 1.8 | 2.8 | 2.3 |
717
+ | GH Archive, write | fastsimdjson `dumpb_arrow` | **1.07** | **2.9** | **4.7** | **4.5** |
718
+ | | polars | 0.47 | 0.78 | 1.1 | 0.91 |
719
+ | | DuckDB | 0.31 | 0.95 | 0.79 | 0.66 |
720
+
721
+ `load_arrow_file` on the same files, from the page cache, reads at 0.67 and
722
+ 1.6 GB/s on one thread, 9.8 and 14.8 GB/s on 32 threads. The benchmark is
723
+ `THREADS=N python bench_arrow.py flat.ndjson:flat gharchive.ndjson:gh
724
+ flat.ndjson:infer`; `path:infer` times any NDJSON file without a schema. The
725
+ flat file comes from
726
+ [simdjson_arrow's `benchmarks/gendata.py`](https://github.com/simdjson/simdjson_arrow/blob/main/benchmarks/gendata.py)
727
+ and the events from GH Archive
728
+ (`curl -sSfL https://data.gharchive.org/2024-03-13-12.json.gz | gunzip > gharchive.ndjson`).
729
+ The charts come from `python doc/make_charts.py arrow`.
730
+
731
+ ### JSON to MessagePack and back
732
+
733
+ From JSON bytes to MessagePack bytes, and back, against the usual ways in
734
+ Python, which decode into Python objects, then encode them:
735
+ `ormsgpack.packb(orjson.loads(s))`, `msgspec.msgpack.encode(msgspec.json.decode(s))`
736
+ and so on. The 22 files of simdjson-data, geometric means of the speeds, in
737
+ GB/s of JSON (read when writing MessagePack, written when writing JSON).
738
+ Python 3.14, msgpack 1.2, orjson 3.13, ormsgpack 1.13, msgspec 0.22, Intel
739
+ Xeon Gold 6338 (Ice Lake), one core.
740
+
741
+ <picture>
742
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_encode_dark.png">
743
+ <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">
744
+ </picture>
745
+
746
+ <picture>
747
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_decode_dark.png">
748
+ <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">
749
+ </picture>
750
+
751
+ Streams: the 304,929 events of an hour of GH Archive (886 MB of NDJSON), with
752
+ `json_to_msgpack(data, ndjson=True, threads=N)` and
753
+ `msgpack_to_json(packed, stream=True, threads=N)`, against orjson with
754
+ ormsgpack (each document) and `msgpack.Unpacker` with orjson (each value), on
755
+ one thread (one thread per core of one socket up to 32 threads, then both
756
+ sockets):
757
+
758
+ <picture>
759
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_ndjson_dark.png">
760
+ <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">
761
+ </picture>
762
+
763
+ | threads | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
764
+ |---|---:|---:|---:|---:|---:|---:|---:|
765
+ | NDJSON to MessagePack | 1.18 | 1.88 | 4.2 | 6.8 | 8.6 | 10.8 | 15.0 |
766
+ | MessagePack to NDJSON | 1.05 | 1.67 | 3.3 | 5.0 | 3.4 | 4.2 | 3.5 |
767
+
768
+ MessagePack to NDJSON stops scaling at about eight threads: one thread must
769
+ find where the values end (MessagePack has no line ends) before the others
770
+ can convert them. The benchmark is `python bench_msgpack.py` (the files of
771
+ `JSONDIR`, by default `simdjson-data/jsonexamples`) and
772
+ `python bench_msgpack.py --ndjson gharchive.ndjson 1 8 32`; the charts come
773
+ from `python doc/make_charts.py msgpack`.
774
+
524
775
  ### Streams with `loads_many`
525
776
 
526
777
  20 MB of NDJSON (5268 objects and arrays, one per line), made from the same
@@ -571,11 +822,5 @@ just created, which takes about 0.1 s here, with or without threads.
571
822
  `release()` frees the parser and the cached strings retained by the calling
572
823
  thread, and they are freed when a Python thread exits. A parser that grows
573
824
  past 64 MB is freed on its own at the end of that call; its caches stay.
574
- * The module is marked free-threading compatible (`Py_MOD_GIL_NOT_USED` on
575
- Python 3.13 and newer), so importing it on a free-threaded build does not
576
- re-enable the GIL. It is tested with many threads parsing, serializing and
577
- sharing views and stream iterators on free-threaded Python 3.14 and 3.15.
578
- On a free-threaded build, `bytearray` and `memoryview` inputs are copied
579
- before parsing, and `dumps` and `dumpb` hold references to the items of the
580
- containers they serialize, since other threads may change them.
581
- Subinterpreters are not supported.
825
+ * Subinterpreters are not supported: the module keeps per-process state (its
826
+ types, and per-thread parsers and string caches).
@@ -11,6 +11,11 @@ Lines), on many threads with free-threaded Python, and can extract only the
11
11
  fields you need from each document. It writes JSON in two ways: `dumps` returns the same `str` as
12
12
  `json.dumps`, and `dumpb` returns the same `bytes` as `orjson.dumps`, as fast
13
13
  as orjson; `dumpb_many` writes NDJSON, on many threads with free-threaded
14
+ Python. `loads_arrow` and `dumpb_arrow` convert NDJSON to Apache Arrow
15
+ tables and back, for pyarrow, polars or DuckDB, on many threads with any
16
+ Python. `json_to_msgpack` and `msgpack_to_json` convert JSON to
17
+ [MessagePack](https://msgpack.org/) and back without building Python objects,
18
+ 3 to 4 times as fast as orjson with ormsgpack, on many threads with any
14
19
  Python.
15
20
 
16
21
  With pip:
@@ -25,8 +30,8 @@ With uv:
25
30
  uv pip install fastsimdjson # in a uv project: uv add fastsimdjson
26
31
  ```
27
32
 
28
- Wheels are available for Linux, macOS and Windows, for Python 3.10 to 3.14,
29
- including free-threaded Python 3.14.
33
+ Wheels are available for Linux, macOS and Windows, for Python 3.10 to 3.15,
34
+ including free-threaded Python 3.14 and 3.15.
30
35
 
31
36
  ## Usage
32
37
 
@@ -259,6 +264,132 @@ On 7.6 GB of GitHub events, `map_many` with three fields ran at 2.8 GB/s on
259
264
  one core of an Intel Xeon Gold 6548N, against 2.2 GB/s with lazy views
260
265
  (`lazy=True`). With 64 threads, it ran at 78 GB/s (lazy views: 61 GB/s).
261
266
 
267
+ ### Arrow: `loads_arrow`, `load_arrow_file` and `dumpb_arrow`
268
+
269
+ ```python
270
+ import pyarrow as pa
271
+ table = pa.table(fastsimdjson.loads_arrow(data)) # inferring the schema
272
+ schema = pa.schema([("id", pa.int64()), ("name", pa.string())])
273
+ table = pa.table(fastsimdjson.load_arrow_file("log.ndjson", schema, threads=8))
274
+ frame = polars.DataFrame(fastsimdjson.loads_arrow(data, schema))
275
+ data = fastsimdjson.dumpb_arrow(table) # b'{"id":1,"name":"x"}\n...'
276
+ data = fastsimdjson.dumpb_arrow(frame, threads=8) # a polars.DataFrame
277
+ ```
278
+
279
+ `loads_arrow(data, schema=None, *, block_size=1048576,
280
+ error_on_unknown_fields=False, validate_skipped=True, threads=None)` reads
281
+ NDJSON (one object per record) into Arrow record batches. The input is
282
+ `bytes`, `bytearray`, `memoryview` or `str`, read in place.
283
+ `load_arrow_file(path, ...)` maps the file in memory and reads it the same way
284
+ (the file must not shrink meanwhile). Both return a `fastsimdjson.ArrowStream`,
285
+ which goes to any library that supports the [Arrow PyCapsule
286
+ interface](https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html),
287
+ without a copy: `pyarrow.table(s)`, `pyarrow.RecordBatchReader.from_stream(s)`,
288
+ `polars.DataFrame(s)`, `duckdb.from_arrow(s)`... Like a `RecordBatchReader`,
289
+ it hands over its batches once (`ValueError` afterwards); `pyarrow.schema(s)`
290
+ gives its schema at any time, and `s.num_rows` the number of records (`None`
291
+ once the batches are taken). fastsimdjson does not depend on pyarrow.
292
+
293
+ * The schema is a `pyarrow.Schema` (or any object with `__arrow_c_schema__`)
294
+ whose fields are booleans, 64-bit integers, unsigned 64-bit integers,
295
+ doubles, strings, structs and lists of these, or null. A field absent from a
296
+ record is null; a key absent from the schema is skipped, or an error with
297
+ `error_on_unknown_fields=True`. Skipped values are checked to be valid
298
+ JSON, unless `validate_skipped=False` (then only their structure is).
299
+ * Without a schema, it is inferred as pyarrow's JSON reader does: `null`,
300
+ `true`/`false`, integers that fit in 64 bits (`int64`), other numbers
301
+ (`double`), strings, objects (structs, with the union of their fields in
302
+ order of first appearance) and arrays (lists). A field of nulls takes the
303
+ type of its other values and integers become doubles next to other
304
+ numbers; other mixes of types raise `ValueError`. Strings stay strings (no
305
+ timestamps).
306
+ * A new batch starts every `block_size` bytes of input. With `threads=N`
307
+ (`threads=0` or `None`: one per processor), N threads read blocks of
308
+ `block_size` bytes, cut at line ends: a record must then fit on one line.
309
+ When that fails, the input is read again on one thread, so that the errors
310
+ (`ValueError`, with the record number and the field) are the same with any
311
+ number of threads.
312
+
313
+ `dumpb_arrow(data, *, write_nulls=True, threads=None)` writes Arrow data as
314
+ NDJSON `bytes`, one object per row: a `pyarrow.Table`, `RecordBatch`,
315
+ `RecordBatchReader` or `StructArray`, a `polars.DataFrame`, a DuckDB
316
+ relation, an `ArrowStream`, or any object with `__arrow_c_stream__` or
317
+ `__arrow_c_array__`. It writes integers of 8 to 64 bits, floats and doubles
318
+ (as `dumpb` writes them, NaN and infinities as `null`), booleans, strings
319
+ (including large strings and string views), structs and lists (including
320
+ large and fixed-size lists); other types raise `ValueError`. With
321
+ `write_nulls=False`, null fields are omitted. With `threads=N`, N threads
322
+ write ranges of rows into the result. The output reads back with
323
+ `loads_arrow`, and with `loads_many(data, format="lines")`.
324
+
325
+ These functions release the GIL and run their threads outside Python, with
326
+ or without free threading. They are built on
327
+ [simdjson_arrow](https://github.com/simdjson/simdjson_arrow), a C++ library
328
+ (vendored).
329
+
330
+ ### MessagePack: `json_to_msgpack` and `msgpack_to_json`
331
+
332
+ ```python
333
+ packed = fastsimdjson.json_to_msgpack(b'{"id": 1, "tags": ["a", "b"], "score": 2.5}')
334
+ # b'\x83\xa2id\x01\xa4tags\x92\xa1a\xa1b\xa5score\xcb@\x04\x00\x00\x00\x00\x00\x00'
335
+ msgpack.unpackb(packed) # {'id': 1, 'tags': ['a', 'b'], 'score': 2.5}
336
+ fastsimdjson.msgpack_to_json(packed) # b'{"id":1,"tags":["a","b"],"score":2.5}'
337
+ stream = fastsimdjson.json_to_msgpack(ndjson, ndjson=True, threads=8) # one value per document
338
+ lines = fastsimdjson.msgpack_to_json(stream, stream=True, threads=8) # NDJSON again
339
+ ```
340
+
341
+ `json_to_msgpack(data, *, ndjson=False, block_size=1048576, threads=None)`
342
+ converts JSON (`bytes`, `bytearray`, `memoryview` or `str`, read in place) to
343
+ MessagePack `bytes` in the most compact encoding: the same bytes as
344
+ `msgpack.packb(json.loads(data))` (but for duplicate keys, which
345
+ `json.loads` drops, and integers beyond 64 bits). Integers take the smallest integer encoding
346
+ (integers beyond 64 bits become doubles), other numbers are doubles, and
347
+ strings, arrays and objects take the smallest header for their size; keys keep
348
+ their order, duplicates too. With `ndjson=True`, the input holds documents
349
+ separated by whitespace (NDJSON, JSON Lines), and each becomes one MessagePack
350
+ value, one after the other.
351
+
352
+ `msgpack_to_json(data, *, stream=False, validate_utf8=True,
353
+ binary_as_base64=True, ext_as_null=False, block_size=1048576, threads=None)`
354
+ converts MessagePack (any bytes-like object) to compact JSON `bytes`. Floats
355
+ get the shortest representation that gives them back, as Python's `repr`
356
+ (`1.0`, not `1`; `1e-05`; NaN and infinities as `null`), binary values as base64 strings, map keys that are not strings as
357
+ strings (`"1"`, `"true"`, `"null"`); extension values (timestamps too) raise
358
+ `ValueError`, or become `null` with `ext_as_null=True`. Strings must be valid
359
+ UTF-8 (unless `validate_utf8=False`). With `stream=True`, the input holds a
360
+ sequence of values (what `json_to_msgpack(..., ndjson=True)` or several
361
+ `msgpack.packb` calls give), and each becomes one line of NDJSON.
362
+
363
+ * Invalid input raises `ValueError`: `"TAPE_ERROR: ... (document 12)"` for
364
+ JSON, `"truncated string (byte 1234)"` for MessagePack.
365
+ * With `threads=N` (`threads=0` or `None`: one per processor), NDJSON and
366
+ streams are converted on N threads, in blocks of about `block_size` bytes.
367
+ A JSON document must then fit on one line; when that fails, the input is
368
+ converted again on one thread, so that errors are the same with any number
369
+ of threads. Single documents use one thread.
370
+ * The functions release the GIL and run their threads outside Python, with or
371
+ without free threading, and write their result straight into the `bytes`
372
+ object (no copy). No Python object is made from the data.
373
+
374
+ They are built on
375
+ [simdjson_msgpack](https://github.com/simdjson/simdjson_msgpack), a C++ library
376
+ (vendored).
377
+
378
+ ### Threads and free-threaded Python
379
+
380
+ The module is marked free-threading compatible (`Py_MOD_GIL_NOT_USED` on
381
+ Python 3.13 and newer), so importing it on a free-threaded build does not
382
+ re-enable the GIL. It is tested with many threads parsing, serializing and
383
+ sharing views and stream iterators on free-threaded Python 3.14 and 3.15.
384
+
385
+ `bytes` and `str` inputs are read in place. A `bytearray` or `memoryview`
386
+ could be changed by another thread while we read it, so it is copied first:
387
+ always by `loads_many`, `parse_many` and `map_many` (the iterator outlives
388
+ the call) and by `loads_arrow`, `json_to_msgpack` and `msgpack_to_json`
389
+ (which release the GIL), and only on a free-threaded build by `loads` and
390
+ `parse`. Likewise, on a free-threaded build, `dumps` and `dumpb` hold
391
+ references to the items of the containers they serialize.
392
+
262
393
  ### `release`
263
394
 
264
395
  `release()` frees the simdjson parser and the string caches kept by the
@@ -267,8 +398,15 @@ calling thread. Views returned by `parse` remain valid.
267
398
  ## Build and test
268
399
 
269
400
  Python 3.10 or newer, and a C++17 compiler (clang, GCC or MSVC). The simdjson
270
- 5.0.7 and simdutf 9.2.1 amalgamations, and zmij 1.2 (shortest float
271
- formatting, MIT license), are already in `vendor/`.
401
+ 5.1.1 and simdutf 9.2.1 amalgamations, simdjson_arrow 0.1.1 (NDJSON to Arrow
402
+ and back: `simdjson_arrow.h` and `simdjson_arrow.cpp`) and simdjson_msgpack
403
+ 0.1.1 (JSON to MessagePack and back: `simdjson_msgpack.h` and
404
+ `simdjson_msgpack.cpp`), both under the Apache-2.0 license, are already in
405
+ `vendor/`. simdjson_arrow includes zmij 1.2 (shortest float formatting, MIT
406
+ license), which simdjson_msgpack, `dumps` and `dumpb` also use
407
+ (`vendor/zmij.h`).
408
+ The tests of the Arrow functions (`tests/test_arrow.py`) run when pyarrow is
409
+ installed (and polars, for one of them); otherwise they are skipped.
272
410
 
273
411
  pip:
274
412
 
@@ -489,6 +627,112 @@ at 0.94 GB/s, `dumpb` on each record at 1.07 GB/s, and `dumpb_many` at
489
627
  |---|---:|---:|---:|---:|
490
628
  | `dumpb_many(records, threads=N)` | 1.3 | 6.0 | 11 | 12 |
491
629
 
630
+ ### NDJSON to Arrow and back
631
+
632
+ Two files: 4 million flat records (611 MB, 9 scalar fields), and 304,929 GH
633
+ Archive events (886 MB), read with a schema of 6 of their fields (two of them
634
+ structs; the rest of each event is skipped), or inferring the schema. Reading
635
+ gives a `pyarrow.Table` (`pyarrow.table(fastsimdjson.loads_arrow(data,
636
+ schema, threads=N))`); the time includes the import into pyarrow. Writing
637
+ starts from that table: fastsimdjson `dumpb_arrow`, polars `write_ndjson` and
638
+ DuckDB `COPY ... TO` (on tmpfs). Python 3.13, pyarrow 26.0, polars 2.1, DuckDB
639
+ 2.0, simdjson 5.1.0, Intel Xeon Gold 6548N (up to 32 threads on the 32 cores
640
+ of one socket; 64 threads on both sockets).
641
+
642
+ <picture>
643
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_1_dark.png">
644
+ <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.70 GB/s, pyarrow 0.18, polars 0.27; GH Archive, fastsimdjson 1.95, pyarrow 0.45, polars 0.53; flat with an inferred schema, fastsimdjson 0.72, pyarrow 0.17, polars 0.08">
645
+ </picture>
646
+
647
+ <picture>
648
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_32_dark.png">
649
+ <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 13.9 GB/s, pyarrow 5.1, polars 4.0; GH Archive, fastsimdjson 28.4, pyarrow 12.1, polars 3.8; flat with an inferred schema, fastsimdjson 13.3, pyarrow 4.8, polars 0.12">
650
+ </picture>
651
+
652
+ <picture>
653
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_1_dark.png">
654
+ <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.96 GB/s, polars 0.46, DuckDB 0.30; GH Archive, fastsimdjson 1.07, polars 0.47, DuckDB 0.31">
655
+ </picture>
656
+
657
+ <picture>
658
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_32_dark.png">
659
+ <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 7.8 GB/s, polars 1.3, DuckDB 2.8; GH Archive, fastsimdjson 4.7, polars 1.1, DuckDB 0.79">
660
+ </picture>
661
+
662
+ All the numbers, in GB/s:
663
+
664
+ | | threads | 1 | 8 | 32 | 64 |
665
+ |---|---|---:|---:|---:|---:|
666
+ | flat, read | fastsimdjson `loads_arrow` | **0.70** | **5.3** | **13.9** | **16.2** |
667
+ | | pyarrow `read_json` | 0.18 | 1.4 | 5.1 | 7.7 |
668
+ | | polars `read_ndjson` | 0.27 | 2.0 | 4.0 | 2.8 |
669
+ | flat, read, inferring the schema | fastsimdjson `loads_arrow` | **0.72** | **5.2** | **13.3** | **12.7** |
670
+ | | pyarrow `read_json` | 0.17 | 1.3 | 4.8 | 6.6 |
671
+ | | polars `read_ndjson` | 0.08 | 0.12 | 0.12 | 0.12 |
672
+ | GH Archive, read | fastsimdjson `loads_arrow` | **1.95** | **12.9** | **28.4** | **25.3** |
673
+ | | pyarrow `read_json` | 0.45 | 3.5 | 12.1 | 15.4 |
674
+ | | polars `read_ndjson` | 0.53 | 3.9 | 3.8 | 3.0 |
675
+ | flat, write | fastsimdjson `dumpb_arrow` | **0.96** | **3.9** | **7.8** | **12.6** |
676
+ | | polars | 0.46 | 1.1 | 1.3 | 1.6 |
677
+ | | DuckDB | 0.30 | 1.8 | 2.8 | 2.3 |
678
+ | GH Archive, write | fastsimdjson `dumpb_arrow` | **1.07** | **2.9** | **4.7** | **4.5** |
679
+ | | polars | 0.47 | 0.78 | 1.1 | 0.91 |
680
+ | | DuckDB | 0.31 | 0.95 | 0.79 | 0.66 |
681
+
682
+ `load_arrow_file` on the same files, from the page cache, reads at 0.67 and
683
+ 1.6 GB/s on one thread, 9.8 and 14.8 GB/s on 32 threads. The benchmark is
684
+ `THREADS=N python bench_arrow.py flat.ndjson:flat gharchive.ndjson:gh
685
+ flat.ndjson:infer`; `path:infer` times any NDJSON file without a schema. The
686
+ flat file comes from
687
+ [simdjson_arrow's `benchmarks/gendata.py`](https://github.com/simdjson/simdjson_arrow/blob/main/benchmarks/gendata.py)
688
+ and the events from GH Archive
689
+ (`curl -sSfL https://data.gharchive.org/2024-03-13-12.json.gz | gunzip > gharchive.ndjson`).
690
+ The charts come from `python doc/make_charts.py arrow`.
691
+
692
+ ### JSON to MessagePack and back
693
+
694
+ From JSON bytes to MessagePack bytes, and back, against the usual ways in
695
+ Python, which decode into Python objects, then encode them:
696
+ `ormsgpack.packb(orjson.loads(s))`, `msgspec.msgpack.encode(msgspec.json.decode(s))`
697
+ and so on. The 22 files of simdjson-data, geometric means of the speeds, in
698
+ GB/s of JSON (read when writing MessagePack, written when writing JSON).
699
+ Python 3.14, msgpack 1.2, orjson 3.13, ormsgpack 1.13, msgspec 0.22, Intel
700
+ Xeon Gold 6338 (Ice Lake), one core.
701
+
702
+ <picture>
703
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_encode_dark.png">
704
+ <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">
705
+ </picture>
706
+
707
+ <picture>
708
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_decode_dark.png">
709
+ <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">
710
+ </picture>
711
+
712
+ Streams: the 304,929 events of an hour of GH Archive (886 MB of NDJSON), with
713
+ `json_to_msgpack(data, ndjson=True, threads=N)` and
714
+ `msgpack_to_json(packed, stream=True, threads=N)`, against orjson with
715
+ ormsgpack (each document) and `msgpack.Unpacker` with orjson (each value), on
716
+ one thread (one thread per core of one socket up to 32 threads, then both
717
+ sockets):
718
+
719
+ <picture>
720
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_ndjson_dark.png">
721
+ <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">
722
+ </picture>
723
+
724
+ | threads | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
725
+ |---|---:|---:|---:|---:|---:|---:|---:|
726
+ | NDJSON to MessagePack | 1.18 | 1.88 | 4.2 | 6.8 | 8.6 | 10.8 | 15.0 |
727
+ | MessagePack to NDJSON | 1.05 | 1.67 | 3.3 | 5.0 | 3.4 | 4.2 | 3.5 |
728
+
729
+ MessagePack to NDJSON stops scaling at about eight threads: one thread must
730
+ find where the values end (MessagePack has no line ends) before the others
731
+ can convert them. The benchmark is `python bench_msgpack.py` (the files of
732
+ `JSONDIR`, by default `simdjson-data/jsonexamples`) and
733
+ `python bench_msgpack.py --ndjson gharchive.ndjson 1 8 32`; the charts come
734
+ from `python doc/make_charts.py msgpack`.
735
+
492
736
  ### Streams with `loads_many`
493
737
 
494
738
  20 MB of NDJSON (5268 objects and arrays, one per line), made from the same
@@ -539,11 +783,5 @@ just created, which takes about 0.1 s here, with or without threads.
539
783
  `release()` frees the parser and the cached strings retained by the calling
540
784
  thread, and they are freed when a Python thread exits. A parser that grows
541
785
  past 64 MB is freed on its own at the end of that call; its caches stay.
542
- * The module is marked free-threading compatible (`Py_MOD_GIL_NOT_USED` on
543
- Python 3.13 and newer), so importing it on a free-threaded build does not
544
- re-enable the GIL. It is tested with many threads parsing, serializing and
545
- sharing views and stream iterators on free-threaded Python 3.14 and 3.15.
546
- On a free-threaded build, `bytearray` and `memoryview` inputs are copied
547
- before parsing, and `dumps` and `dumpb` hold references to the items of the
548
- containers they serialize, since other threads may change them.
549
- Subinterpreters are not supported.
786
+ * Subinterpreters are not supported: the module keeps per-process state (its
787
+ types, and per-thread parsers and string caches).