Skip to content
NeuroJSONPublic

About

pmat and jdai - high performance scientific data format and parsers based on NeuroJSON JData

Topics

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

jdai

jdai: a fast, portable C++11 library and Python/MATLAB/Octave toolbox for JSON, BJData, UBJSON and MessagePack with JData annotations

CI Benchmark Wheels PyPI

Table of Contents

What's New

Coming in the next release

  • YAML (experimental) — .yaml/.yml files (or format="yaml") are read and written as jsonlab's loadyaml/saveyaml read and write them, with the same JData annotations as JSON: block and flow collections, quoted, plain and block (|, >) scalars, comments, anchors, aliases and merge keys, and several documents. Not read: complex keys (? ). In Python, jdai.dumps(x, format="yaml") gives a str.
  • Faster loads — large arrays in huge pages when the kernel has them to spare, their page faults taken on several threads, and zstd and lz4 decoded straight into the arrays: loading 256 MiB of compressed doubles is 2-3 times faster (zstd+shuffle 351 -> 97 ms on a 64-core machine).

jdai 0.1.1

  • Records with integer fields as a structure of arrays — a list of dicts (or BJData records) with integer fields is written as a structure of arrays, as soa= asks: an integer column takes the smallest type that holds all its values. In 0.1.0, a Python int's own smallest type differed from value to value, and such lists were always written as lists of objects (and load(..., soa="columns") gave them back as records).

jdai 0.1.0

  • First release — one C++11 library, with no dependencies beyond the C++ standard library, that reads and writes JSON, BJData (Draft 4), UBJSON and MessagePack, and decodes and encodes JData annotations: N-D arrays of any element type and memory order, complex, sparse and compressed arrays, structure-of-arrays records, enumerations and more.
  • Codecs built in — zlib, gzip, zstd, lz4, lz4hc, lzma, lzip and xz, plus base64; zlib is block-parallel (zlibmt: still a standard zlib stream, inflated on several threads), and payloads can be byte-shuffled.
  • N-D chunks — arrays can be compressed in N-D tiles (chunks="auto" picks tiles of about 256 KiB to 1 MiB), so that a slice, a line or a block is read, or written back, by decompressing only the tiles it meets.
  • JSON-Mmap — .pmat/.jmat files carry a table of the byte locations of their values, so that one member is read, or updated in place, without parsing the rest of the file.
  • An intuitive C++ interface — neurojson::jdata, written like nlohmann/json (j["a"]["b"] = 1, initializer lists, get<T>(), items(), parse/dump), with typed N-D arrays from nested braces (matrix({{1, 2}, {3, 4}})), your own types as records, and faster than nlohmann/json at building, looking up, parsing and binary I/O.
  • Python, MATLAB and Octave — a Python module (numpy arrays in and out, zero-copy views of mapped files), and a MEX file that jsonlab's loadjson, loadbj, savejson and savebj use by themselves when it is on the path.

Introduction

jdai ("JData Interface") is a fast and compact reader and writer of the JSON-based data formats of the NeuroJSON project. A JSON or binary JSON document is read into a value (neurojson::jdata in C++, a nlohmann/json-style class), or straight into the caller's objects (Python dicts and numpy arrays, MATLAB structs and arrays), with the JData annotations it holds decoded on the way: an object such as

{"_ArrayType_": "single", "_ArraySize_": [181, 217, 181], "_ArrayZipType_": "zstd",
 "_ArrayZipSize_": [1, 7109137], "_ArrayZipData_": "KLUv/WBQ..."}

becomes a 181 x 217 x 181 array of floats. Writing does the reverse, choosing the annotations a value needs. The formats are chosen from the file name (.json/.jdt/.jnii/.jmsh/.jbids: JSON; .bjd/.jdb/.bnii/.bmsh/.pmat/.jbat: BJData; .ubj: UBJSON; .msgpack/.mpk: MessagePack; .yaml/.yml: YAML, experimental) or from the content.

jdai follows the specifications it implements, and is checked against them and against jsonlab, the reference implementation, on every commit:

  • JSON (RFC 8259), with exact, locale-independent number conversion and the shortest text that reads back the same double;
  • BJData Draft 4 and UBJSON, including typed N-D arrays, structure-of-arrays containers and the extension type, and MessagePack;
  • JData annotations, including compressed and chunked arrays, byte shuffling, enumerations, and JData files of several roots;
  • JSON-Mmap tables for direct access to members.

The work is done in C++ with up to 8 threads: compression and decompression of large payloads, of the chunks of an array, and of the arrays of a document. Among the codecs, lz4 is the fastest; zstd gives smaller files at a similar speed when decoding; zlib/gzip are the most widely readable (jsonlab reads them with no extra toolbox, Python with its standard library); lzma/xz compress most, slowly.

Installation

The Python module is on PyPI, with prebuilt wheels for Linux (x86_64 and aarch64), macOS (Intel and Apple Silicon) and Windows, for Python 3.9 to 3.13:

pip install jdai

The C++/C library, the jdaiconv tool and the MEX file for MATLAB and Octave are built from source. jdai builds from source with CMake 3.10 or newer and a C++11 compiler (GCC 4.8 or newer, Clang, Apple Clang, or MSVC; the CI uses Visual Studio 2022). The library, the jdaiconv tool, the tests, the Python module and the MEX file share one source tree:

git clone https://github.com/NeuroJSON/jdai.git jdai
cd jdai
cmake -S . -B build
cmake --build build -j
ctest --test-dir build

This builds the static library libjdai.a (jdai_static.lib with MSVC), the shared library libjdai.so/libjdai.dylib/jdai.dll, and jdaiconv. cmake --install build installs them with the headers (include/jdai).

To build the Python module from the source tree instead (with scikit-build-core):

pip install .

For MATLAB and Octave, see Using jdai in MATLAB and GNU Octave.

Using jdai in Python

import numpy as np
import jdai

obj = {"name": "scan", "image": np.zeros((256, 256, 64), np.uint16), "tags": ["a", "b"]}

jdai.save(obj, "scan.bjd", compression="zstd")   # format from the file name
back = jdai.load("scan.bjd")                     # numpy arrays come back with their dtype and shape

b = jdai.dumps(obj)                              # BJData bytes
t = jdai.dumps(obj, format="json", indent=2)     # JSON text (arrays as JData annotations)
obj = jdai.loads(b)

ann = jdai.encode(obj, compression="zlib")       # the JData-annotated form (dicts)
obj = jdai.decode(ann)

Reading part of a file:

jdai.save({"meta": {"subject": "s01"}, "image": vol, "n": 7}, "scan.pmat",
         compression="zstd", shuffle=True, chunks="auto")   # N-D tiles, with a JSON-Mmap table

jdai.load("scan.pmat", keys="n")                  # 7: only those bytes are parsed
jdai.load("scan.pmat", keys="$.meta.subject")     # a JSON-Mmap path
jdai.load_region("scan.pmat", "image", (90,))     # one slice: only the tiles it meets are decoded
jdai.update("scan.pmat", "n", 8)                  # in place
jdai.update_region("scan.pmat", "image", (slice(0, 32), slice(0, 32), slice(0, 32)), block)
jdai.load("raw.pmat", view=True)                  # uncompressed arrays as zero-copy views of the file

The options (compression, level, shuffle, chunks, soa, indent, nonfinite, ...), the mapping between Python and stored values, and the JSON-Mmap functions are described in bindings/python/README.md. jdai.set_threads(n) sets the number of threads.

More complete programs are in examples/python: hello_jdai.py (documents, text, bytes and members of a file), arrays.py (numpy arrays, compression, tiles, regions read and written, zero-copy views) and tables.py (records as a structure of arrays, enumerations, other Python values).

Using jdai in MATLAB and GNU Octave

jdai gives jsonlab a compiled backend: the jdai class (jdai.m) and the MEX file behind it, jdai_mex.mexa64 (MATLAB) or jdai_mex.mex (Octave). Once they are on the path, jsonlab's loadjson, loadbj, loadyaml, savejson, savebj and saveyaml use them by themselves (their Backend option: 'auto', the default; 'mex' requires it; 'm' never uses it), with the same results as jsonlab's .m code, 4 to 600 times faster. Options or values jdai does not handle fall back to the .m code.

To build it, compile the static library first, then run make_jdai in MATLAB or Octave:

cmake -S . -B build -DJDAI_BUILD_SHARED=OFF -DJDAI_BUILD_TESTS=OFF -DJDAI_BUILD_TOOLS=OFF
cmake --build build -j
cd bindings/matlab
make_jdai('../../build/libjdai.a')
addpath(pwd)                  % with jsonlab on the path too

data = loadbj('scan.bjd');    % jdai does the work
savejson('', data, 'FileName', 'scan.json', 'Compression', 'zlib');

Its methods can also be called directly (options as a struct or name/value pairs; help jdai):

[data, needdecode] = jdai.loadbj('scan.bjd');
bytes = jdai.savebj('', data, 'Compression', 'zstd');
text = jdai.saveyaml('', data);
jdai.threads(4);
jdai.version()

test_jdai checks the MEX file against jsonlab's .m readers and writers (test_jdai('loadbj'), 'loadjson', 'savebj', 'savejson', 'mmap').

Using jdai in C++ and C

C++ (#include "jdai/jdai.hpp", C++11, link jdai_static or jdai::jdai in CMake) has a nlohmann/json-style interface, neurojson::jdata. Code written for nlohmann/json reads the same, and typed N-D arrays, compression and the binary formats come with it:

#include "jdai/jdai.hpp"
using neurojson::jdata;
using namespace neurojson::literals;

jdata j = {
    {"name", "scan"},
    {"tags", {"a", "b"}},                                    // a list
    {"affine", neurojson::matrix({{1., 0.}, {0., 1.}})},     // a typed 2x2 double array
    {"img", neurojson::zeros<float>({181, 217, 181})},       // a typed N-D array of zeros
    {"spectrum", std::vector<double>(1024)}                  // a typed 1-D array
};
j["meta"]["subject"] = "s01";                                // members are created on assignment
j["tags"].push_back("c");
std::string name = j["name"];                                // or j["name"].get<std::string>()
std::vector<double> s = j["spectrum"];                       // from a typed array or a list
auto img = j["img"].nd<float>();                             // a typed view: img(i, j, k), img.shape()
img(90, 108, 90) = 1.0f;
for (auto& el : j.items()) { el.key(); el.value(); }

std::string text = j.dump(2);                                // JSON (small arrays as plain lists)
std::vector<std::uint8_t> bytes = jdata::to_bjdata(j);       // also to_msgpack, to_ubjson
jdata k = jdata::parse(text), b = jdata::from_bjdata(bytes);
jdata t = R"({"a": [1, 2]})"_jdata;
t.at_path("$.a[1]") = 3;                                     // JSON-Mmap paths, and JSON Pointers: at_pointer("/a/1")

neurojson::SaveOptions o;
o.jdata.compression = "zstd";
o.jdata.shuffle = -1;                                        // byte-shuffle by the element size
o.jdata.chunk_auto = true;                                   // N-D tiles for large arrays
j.save("scan.pmat", o);                                      // format from the file name
jdata back = jdata::load("scan.pmat");

Numeric arrays and matrices are written as nested braces. matrix (the same function as ndarray) takes the shape from the nesting and the element type from the numbers, promoting them as numpy does:

using neurojson::matrix;

jdata v = matrix({1, 2, 3});                          // int32, 3
jdata m = matrix({{1, 2.5}, {3, 4}});                 // double, 2x2 (any double makes it double)
jdata f = matrix({{1.f, 2.f}, {3.f, 4.f}});           // single, 2x2
jdata c = matrix({{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}); // int32, 2x2x2
jdata u = matrix<std::uint8_t>({{1, 2}, {3, 4}});     // the type given: each number checked to fit
jdata z = neurojson::zeros<float>({64, 64, 64});      // a shape, zero-filled

Any double, or floats mixed with integers, give double; floats alone single; integers the widest of their types (signed when any is signed, wide enough for the unsigned ones); booleans logical. Variables work as literals do, {{1}, {2}} is a 2x1 column, and ragged braces are an error.

User types convert with a macro, or with to_jdata/from_jdata functions in their namespace, as nlohmann/json's to_json/from_json; a list of them is stored as records (a structure of arrays in BJData):

struct Point { double x, y; std::string label; };
JDAI_DEFINE_TYPE(Point, x, y, label)                          // in Point's namespace

std::vector<Point> pts(1000);
jdata p = pts;                                               // [{"x":..,"y":..,"label":..}, ...]
std::vector<Point> again = p;

Where it differs from nlohmann/json, it does so to keep JData's types and arrays:

  • numbers keep their C++ type (int8_t, float, uint64_t, ...), as BJData can store it; get<T>() checks the range (neurojson::out_of_range) and the kind (neurojson::type_error);
  • a container of numbers (std::vector<double>, std::array<int, 3>, ...) becomes a typed 1-D array, not a list of values (jdata::list(v) makes a list); j["v"][3] on such an array is a type_error: its elements are read and written through j["v"].nd<double>();
  • dump() writes real arrays of 1 or 2 dimensions as plain lists, and larger or complex ones as JData annotations; dump(indent, true) annotates them all, which keeps their element types.

A lookup index makes member access in large objects fast; members keep their insertion order, as in nlohmann::ordered_json. Measured with bench/bench_cxx_api.cpp (AMD Ryzen 9 5900X, one thread, the best of 7 runs, milliseconds; nlohmann/json 3.11.3):

neurojson::jdata nlohmann::json nlohmann::ordered_json
an object of 100000 members, j[key] = i 11.7 16.3 12448
1e6 lookups in an object of 1000 members, j.at(key) 37.8 73.2 1241
10000 small documents from initializer lists 5.8 8.0 8.6
std::vector<double> of 1e6 to a value 0.23 25.1 20.3
the value back to std::vector<double> 1.1 1.3 1.3
the 1e6 doubles to BJData / from BJData 1.9 / 0.9 8.5 / 61.7 7.9 / 79.6
parse citm_catalog.json / canada.json 3.2 / 10.4 7.9 / 23.2 12.0 / 23.1
dump citm_catalog.json / canada.json 1.2 / 7.3 1.2 / 6.7 1.2 / 7.0

More complete programs are in examples/: hello_jdata.cpp (documents, text and BJData), arrays.cpp (matrices, volumes, views, compression and tiles, reading single members back) and user_types.cpp (your own types and standard containers); CMake builds them and ctest runs them.

The same library is also reachable at a lower level, in namespace jdai: the parsers and writers with all their options, parsing straight into your own objects (builder.hpp), N-D chunk access (jdai::ChunkedArray) and in-place updates of files (jdai::update); include/jdai/jdai.hpp documents them.

C (#include "jdai/jdai.h", C99) has the same interface as one constant struct, JData, so that calls read as they do in the other languages:

#include "jdai/jdai.h"

double affine[4][4] = {{1, 0, 0, -90}, {0, 1, 0, -126}, {0, 0, 1, -72}, {0, 0, 0, 1}};

jdai_value* doc = JData.object();
JData.set(doc, "name", JData.string("scan"));             /* set and append take ownership */
JData.set(doc, "age", JData.integer(31));
JData.set(doc, "affine", JData.matrix(JDAI_DOUBLE, 4, 4, affine));   /* a typed 4x4 */
JData.set(doc, "subject", JData.parse("{\"id\": \"s01\"}"));

jdai_save_options o = JData.options();
o.compression = "zstd";
JData.save_with("scan.pmat", doc, &o);                    /* or JData.save(path, doc) */

jdai_value* back = JData.load("scan.pmat");
printf("%s %s\n", JData.as_string(JData.get(back, "name"), NULL),
                  JData.as_string(JData.get(back, "$.subject.id"), NULL));   /* or "/subject/id" */
char* text = JData.dumps(back, 2);                        /* JSON text */
JData.release_buffer(text);
JData.release(back);
JData.release(doc);

Functions return NULL, or a negative number, on failure, and JData.error() says why. With C11, JDAI_VAL(x) makes a value of x's C type: JDAI_VAL(31) an int32, JDAI_VAL(2.5) a double, JDAI_VAL("text") a string. Every member of JData is also a plain function (jdai_load, jdai_get, jdai_new_matrix, ...), and C++ code uses neurojson::jdata instead (in C++, jdai is a namespace, so the JData object is declared for C only). See examples/c/hello_jdata.c.

The headers in include/jdai document the rest: value.hpp and convert.hpp (the value and its conversions), json.hpp and bjdata.hpp (the parsers and writers), jdata.hpp (the annotations), codec.hpp (the codecs), mmap.hpp (JSON-Mmap tables) and builder.hpp (parsing into your own objects).

The jdaiconv command line tool

jdaiconv converts between the formats, compressing arrays on the way:

jdaiconv data.json data.bjd                      # JSON to BJData
jdaiconv -z zstd -s data.bjd data.jdt            # to JSON with zstd-compressed, shuffled arrays
jdaiconv -z zlib --chunks auto vol.bnii vol.pmat # N-D tiles
jdaiconv -p data.bjd                             # a summary of the structure
jdaiconv -v data.bjd                             # only check that it parses

jdaiconv -h lists the options.

Compile jdai

The CMake options are

option default builds
JDAI_BUILD_SHARED ON the shared library, beside the static one
JDAI_BUILD_TOOLS ON jdaiconv
JDAI_BUILD_TESTS ON the C++ and C tests (ctest), and the Python tests when the module is built
JDAI_BUILD_PYTHON OFF the Python module (needs pybind11 and numpy)
JDAI_BUILD_EXAMPLES ON the C++ examples (examples/cpp), run by ctest with the Python ones (examples/python) when the module is built
JDAI_BUILD_BENCH OFF bench_jdai, and bench_cxx_api (against nlohmann/json when its header is found, or -DJDAI_NLOHMANN_INCLUDE=dir)

for example

cmake -S . -B build -DJDAI_BUILD_PYTHON=ON -DJDAI_BUILD_BENCH=ON
cmake --build build -j
ctest --test-dir build --output-on-failure
PYTHONPATH=build/bindings/python python -m pytest tests/python

The CI (.github/workflows/ci.yml) builds and tests jdai with GCC (4.8, 5 and current), Clang, AddressSanitizer and UndefinedBehaviorSanitizer on Linux, Apple Clang on macOS and MSVC on Windows, and checks the MEX file against jsonlab in MATLAB and Octave. Python wheels are built by .github/workflows/wheels.yml (cibuildwheel).

Performance

Choosing the options

How an array is stored decides what reading it costs. A compressed array is always decoded (there is no zero-copy view of compressed data); one compressed as a single payload is decoded whole even to read one slice; one stored in N-D tiles is decoded only where a read meets it. The options below are those of the Python module. In C++ they are members of neurojson::SaveOptions::jdata (compression, level, shuffle, chunks/chunk_auto, compress_min; see the example after the table); jdaiconv, the C jdai_save_options and jsonlab's options for the MEX file have most of them (the C interface has no chunk setting yet).

the data, the need options what it gives
The default we recommend: numeric arrays where a small file and fast reads both matter .pmat, compression="zstd", shuffle=True, chunks="auto" byte shuffling makes numbers compress much better (256 MiB of noisy doubles: 194 MB instead of 254 MB); tiles of 256 KiB to 1 MiB are decoded on all threads and make slices and blocks cheap
Files that jsonlab without zmat, or Python's standard library, must read compression="zlib" (with shuffle and chunks as above) jdai's zlib is block-parallel (zlibmt) but its output is a standard zlib stream; within a few percent of zstd's size; single-threaded zstd decodes 10-40% faster, and with 8 threads zlib loads as fast or faster
The fastest saves and loads, size second compression="lz4", shuffle=True 1.5 to 2 times faster than zstd to write; files 5-10% larger
The fastest reads of large arrays from a local disk or RAM no compression, .pmat, load(..., view=True) arrays are views of the mapped file: no copy, pages read when used (little-endian numeric arrays; complex and logical ones are copied)
Slices, lines or blocks of big arrays, updated in place chunks={"shape": "auto", "index": True, "slack": 16}, then load_region / update_region the index finds a tile without reading the others; spare bytes after each tile let a changed tile be written back in place
Tables: a list of records, or columns a list of dicts with the same keys (stored as structure-of-arrays columns), compression="zstd" or "lz4", shuffle=True string columns with repeated values are stored as enumerations by default: a 1-million-row table takes 5.7 MB, against Parquet's 10.0 MB
Many small arrays (a few hundred elements each) no compression (the default compress_min=300 leaves arrays of up to 300 elements alone) 10000 arrays of 100 doubles take 8.7 MB uncompressed and 9.9 MB with zstd, which is 3 to 5 times slower
Documents of many small values .pmat (BJData with a JSON-Mmap table); load(..., keys=...) to read members one member read in a millisecond from a 25 MB document; update rewrites it in place
Text that people read or edit .jmat/.json with the same options base64 payloads are a third larger than binary ones, and text is slower to parse

The recommended default in C++:

neurojson::SaveOptions o;
o.jdata.compression = "zstd";                 // or "zlib" for files every reader can open
o.jdata.shuffle = -1;                         // byte-shuffle by the element size
o.jdata.chunk_auto = true;                    // N-D tiles for arrays of 2 MiB or more
doc.save("scan.pmat", o);                     // doc: a neurojson::jdata

neurojson::LoadOptions lo;
lo.keys = {"meta", "n"};                      // only these members, through the file's table
neurojson::jdata part = neurojson::jdata::load("scan.pmat", lo);

A few rules behind these choices: chunks applies only to compressed arrays (without compression it is ignored); update_region needs N-D tiles (chunks with a shape or "auto"); and jdai.update writes a member with the options it is given, not those it was saved with (tiled arrays keep their tiles), so pass the same compression, shuffle and chunks again.

How jdai compares

Measured with bench/bench_best.py and bench/bench_volume.py on an AMD Ryzen 9 5900X (8 threads for every library that has them), files on a RAM disk, the best of 3 runs (7 for the volume); times in milliseconds. Each format is used at its best: HDF5 through h5py (with hdf5plugin's codecs), Arrow IPC memory-mapped and Parquet through pyarrow, Blosc2 NDim arrays through python-blosc2. "Load" includes summing the arrays, so that lazily mapped data is read too.

Eight arrays of 2048 x 2048 doubles (256 MiB, a smooth signal plus noise):

format save load read one array update one array MB
jdai .pmat, uncompressed, view=True 95 30 4.0 4.4 268.4
jdai .pmat, zstd + shuffle 408 325 14.9 96 193.6
jdai .pmat, zlib + shuffle 415 222 16.8 88 195.9
jdai .pmat, lz4 + shuffle 228 272 29.6 48 203.5
HDF5, uncompressed 99 482 16.0 5.0 268.4
HDF5, zstd 390 644 32.9 41 254.6
HDF5, Blosc2 zstd 2135 2148 221.3 259 203.6
Arrow IPC, uncompressed 103 63 11.5 783 268.5
Arrow IPC, zstd 166 140 68.7 1217 253.6
Parquet, zstd 743 121 26.6 884 262.0
numpy .npz, compressed 7014 1211 116.9 8343 242.1

jdai makes the smallest files, reads one compressed array about as fast as any other format, and updates one in place; Arrow, Parquet and .npz write the whole file again to change one array. Arrow and Parquet load all of these arrays faster than jdai does compressed, but they barely compress them (254 to 262 MB, against jdai's 194); uncompressed, jdai's views are the fastest.

A table of 1 million rows (int64, two float64, int32, bool, a 20-value category and a 50000-value string column):

format save load all read one column MB
jdai .pmat, zstd + shuffle 88 94 4.3 5.7
jdai .pmat, uncompressed, view=True 55 86 0.10 32.6
Arrow IPC, zstd 106 998 10.6 10.9
Parquet, zstd 167 1027 9.6 10.0
HDF5, zstd 560 681 10.4 95.6

"Load all" gives numpy arrays and Python strings; kept as an Arrow table, Arrow's load takes a few milliseconds. Reading the string column alone, Arrow is faster (46 ms against jdai's 75).

A 3-D volume (the colin27 atlas, 181 x 217 x 181 float32, 28 MB) in 32^3 tiles:

format save whole slice line 32^3 block voxel update block update voxel MB
jdai, zstd, tiles + index + slack 28 7.9 0.69 0.23 0.40 0.10 2.2 0.86 13.4
jdai, lz4, tiles + index + slack 13 6.5 0.46 0.17 0.24 0.07 1.1 0.23 14.2
jdai, zstd, one payload 95 8.4 6.94 6.91 7.42 7.05 12.5
Blosc2 NDim, zstd level 1 130 13.4 2.06 0.52 0.54 0.25 8.2 0.60 12.4
HDF5, zstd 45 19.0 2.62 0.59 0.88 0.28 2.3 0.49 12.6

The same volume in one compressed payload costs a full decode for any read. In tiles, jdai reads the whole volume and every region 1.4 to 4 times faster than Blosc2 and HDF5 with the same tile shape and codec; with zstd, Blosc2 and HDF5 update a single voxel faster.

Documents of many small values (a 25 MB list of GitHub event records; Python):

save load read one member update one member
jdai .pmat 65 138 0.97 2.6
orjson 24 123 142 169
msgspec (MessagePack) 22 107 128 154
pysimdjson (lazy) 158 23

Loading a whole document takes about as long with every library (the time goes on creating the Python objects). Saving one from Python objects is where jdai is behind (3 times orjson); reading or changing one member through the JSON-Mmap table is 25 to 150 times faster than parsing the document.

Running the benchmarks

sh bench/compare.sh builds jdai and runs the comparison on your machine, against numpy's .npz, HDF5 (h5py, hdf5plugin), Apache Arrow and Parquet (pyarrow), Blosc2, pyjdata, bjdata, orjson and msgpack, in a Python venv it makes; --full adds bench_best.py, which the tables above come from. The CI runs it on every commit and posts the tables on the run's summary page. bench/README.md has the full results, MATLAB and Octave included.

Contribution and Feedback

jdai is an open-source project. This means you can not only use it and modify it as you wish, but also you can contribute your changes back to jdai so that everyone else can enjoy the improvement. For anyone who want to contribute, please download the jdai source code from its source code repository by using the following command:

git clone https://github.com/NeuroJSON/jdai.git jdai

or browse the github site at https://github.com/NeuroJSON/jdai

You can make changes to the files as needed. Once you are satisfied with your changes, and ready to share them with others, please submit your changes as a "pull request" on github. The project maintainer, Dr. Qianqian Fang, will review the changes and choose to accept the patch.

We appreciate any suggestions and feedback from you. Please use the NeuroJSON forum to report any questions you may have regarding jdai:

NeuroJSON forum

Acknowledgement

jdai's DEFLATE (zlib, gzip) and Zstandard codecs, its parsers and writers are its own. It bundles the below open-source libraries, unmodified (see licensing.json):

  1. LZ4: https://github.com/lz4/lz4 (version 1.10.0)
    • Copyright (c) 2011-2020, Yann Collet
    • License: BSD 2-Clause License (third_party/lz4/LICENSE)
    • Used for: the lz4 and lz4hc codecs
  2. LZMA SDK: https://www.7-zip.org/sdk.html (version 26.00)
    • Author: Igor Pavlov
    • License: public domain
    • Used for: the lzma, lzip and xz codecs
  3. Ryu: https://github.com/ulfjack/ryu
    • Copyright 2018 Ulf Adams
    • License: Apache License 2.0 or Boost Software License 1.0
    • Used for: the shortest decimal text of floating-point numbers in the JSON writer
  4. fast_float: https://github.com/fastfloat/fast_float (version 6.1.6)
    • Copyright (c) 2021 The fast_float authors (Daniel Lemire and contributors)
    • License: Apache License 2.0, MIT License or Boost Software License 1.0
    • Used for: exact, locale-independent number parsing in the JSON reader

About

pmat and jdai - high performance scientific data format and parsers based on NeuroJSON JData

Topics

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages