loaderx 1.5.7__tar.gz → 1.6.2__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.
- {loaderx-1.5.7/loaderx.egg-info → loaderx-1.6.2}/PKG-INFO +166 -143
- {loaderx-1.5.7 → loaderx-1.6.2}/README.md +164 -141
- loaderx-1.6.2/loaderx/__init__.py +22 -0
- loaderx-1.5.7/loaderx/zrecord.py → loaderx-1.6.2/loaderx/_zrecord.py +11 -30
- {loaderx-1.5.7 → loaderx-1.6.2}/loaderx/dataloader.py +46 -18
- {loaderx-1.5.7 → loaderx-1.6.2}/loaderx/utils.py +18 -14
- loaderx-1.5.7/loaderx/dataset.py → loaderx-1.6.2/loaderx/zrecord.py +53 -47
- loaderx-1.5.7/loaderx/sampler.py → loaderx-1.6.2/loaderx/zsampler.py +3 -1
- {loaderx-1.5.7 → loaderx-1.6.2/loaderx.egg-info}/PKG-INFO +166 -143
- {loaderx-1.5.7 → loaderx-1.6.2}/loaderx.egg-info/SOURCES.txt +2 -2
- {loaderx-1.5.7 → loaderx-1.6.2}/pyproject.toml +2 -2
- {loaderx-1.5.7 → loaderx-1.6.2}/scripts/bench.py +6 -6
- {loaderx-1.5.7 → loaderx-1.6.2}/src/zrecord/format.zig +4 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/src/zrecord/storage.zig +49 -25
- {loaderx-1.5.7 → loaderx-1.6.2}/src/zrecord.zig +97 -71
- {loaderx-1.5.7 → loaderx-1.6.2}/tests/test_loaderx.py +160 -290
- loaderx-1.5.7/loaderx/__init__.py +0 -24
- {loaderx-1.5.7 → loaderx-1.6.2}/LICENSE +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/MANIFEST.in +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/build.zig +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/build.zig.zon +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/loaderx/_lib.py +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/loaderx.egg-info/dependency_links.txt +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/loaderx.egg-info/requires.txt +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/loaderx.egg-info/top_level.txt +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/scripts/build_wheels.py +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/setup.cfg +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/setup.py +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/src/zrecord/codec.zig +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/src/zrecord/exec.zig +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/src/zsampler.zig +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/src/zstd/c.zig +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/COPYING +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/LICENSE +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/allocations.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/bits.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/bitstream.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/compiler.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/cpu.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/debug.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/debug.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/entropy_common.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/error_private.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/error_private.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/fse.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/fse_decompress.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/huf.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/mem.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/pool.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/pool.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/portability_macros.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/threading.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/threading.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/xxhash.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/xxhash.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/zstd_common.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/zstd_deps.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/zstd_internal.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/common/zstd_trace.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/clevels.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/fse_compress.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/hist.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/hist.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/huf_compress.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_compress.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_compress_internal.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_compress_literals.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_compress_literals.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_compress_sequences.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_compress_sequences.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_compress_superblock.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_compress_superblock.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_cwksp.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_double_fast.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_double_fast.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_fast.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_fast.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_lazy.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_lazy.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_ldm.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_ldm.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_ldm_geartab.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_opt.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstd_opt.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstdmt_compress.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/compress/zstdmt_compress.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/decompress/huf_decompress.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/decompress/zstd_ddict.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/decompress/zstd_ddict.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/decompress/zstd_decompress.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/decompress/zstd_decompress_block.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/decompress/zstd_decompress_block.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/decompress/zstd_decompress_internal.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/dictBuilder/cover.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/dictBuilder/cover.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/dictBuilder/divsufsort.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/dictBuilder/fastcover.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/dictBuilder/zdict.c +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/zdict.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/zstd.h +0 -0
- {loaderx-1.5.7 → loaderx-1.6.2}/vendor/zstd/lib/zstd_errors.h +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: loaderx
|
|
3
|
-
Version: 1.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 1.6.2
|
|
4
|
+
Summary: Zrecord typed persistent stores and the Loaderx data loader for single-machine AI pipelines
|
|
5
5
|
Author-email: Ben0i0d <ben0i0d@foxmail.com>
|
|
6
6
|
License: MIT License
|
|
7
7
|
|
|
@@ -48,6 +48,10 @@ Dynamic: license-file
|
|
|
48
48
|
# Loaderx
|
|
49
49
|
A compact, high-performance persistent record store with zero-copy batch gathering and transparent per-record compression, designed for single-machine AI training and serving pipelines
|
|
50
50
|
|
|
51
|
+
Zrecord is the typed persistent store; Loaderx is the sampler and prefetch
|
|
52
|
+
loader that consumes Zrecord streams. They currently ship together while both
|
|
53
|
+
layers mature, but their public responsibilities remain separate.
|
|
54
|
+
|
|
51
55
|
```
|
|
52
56
|
pip install loaderx
|
|
53
57
|
```
|
|
@@ -73,13 +77,13 @@ loaderx is built around several core principles:
|
|
|
73
77
|
## Quick Start
|
|
74
78
|
```python
|
|
75
79
|
from loaderx.utils import from_numpy
|
|
76
|
-
from loaderx.
|
|
80
|
+
from loaderx.zrecord import DenseStore
|
|
77
81
|
from loaderx.dataloader import DataLoader
|
|
78
82
|
|
|
79
83
|
from_numpy('train_data', np.load('data.npy', mmap_mode='r'))
|
|
80
84
|
from_numpy('train_label', np.load('label.npy', mmap_mode='r'))
|
|
81
85
|
|
|
82
|
-
loader = DataLoader({'data':
|
|
86
|
+
loader = DataLoader({'data': DenseStore('train_data'), 'label': DenseStore('train_label')},
|
|
83
87
|
transform=lambda batch: batch)
|
|
84
88
|
|
|
85
89
|
for i, batch in enumerate(loader):
|
|
@@ -100,7 +104,7 @@ plain dense batch ready for the model.
|
|
|
100
104
|
```python
|
|
101
105
|
import numpy as np
|
|
102
106
|
from loaderx.utils import from_numpy
|
|
103
|
-
from loaderx.
|
|
107
|
+
from loaderx.zrecord import DenseStore
|
|
104
108
|
|
|
105
109
|
from_numpy('train_data', np.load('data.npy', mmap_mode='r'))
|
|
106
110
|
from_numpy('train_label', np.load('label.npy', mmap_mode='r'))
|
|
@@ -109,18 +113,18 @@ from_numpy('train_label', np.load('label.npy', mmap_mode='r'))
|
|
|
109
113
|
from_numpy('train_data', images, codec='zstd_dict')
|
|
110
114
|
```
|
|
111
115
|
One record per slice along axis 0; a 1-D array (the usual shape of a label set)
|
|
112
|
-
becomes a
|
|
116
|
+
becomes a store of scalar records. The conversion streams in bounded chunks, so an
|
|
113
117
|
mmapped array is never fully materialized. Open the result with
|
|
114
|
-
:class:`
|
|
118
|
+
:class:`DenseStore`:
|
|
115
119
|
|
|
116
|
-
ds =
|
|
120
|
+
ds = DenseStore('train_data')
|
|
117
121
|
|
|
118
122
|
The store carries a single ``schema.msgpack`` recording the kind (``"dense"``
|
|
119
123
|
or ``"ragged"``), the per-sample dtype, and the shape contract — one
|
|
120
124
|
``item_shape`` for a dense store, one shape per record for a ragged store. That
|
|
121
|
-
is the only loaderx-level metadata.
|
|
122
|
-
|
|
123
|
-
(
|
|
125
|
+
is the only loaderx-level metadata. The native zrecord engine beneath it is an
|
|
126
|
+
implementation detail; raw bytes and pre-encoded images use a
|
|
127
|
+
``RaggedStore(path, dtype=np.uint8)`` rather than a second public storage API.
|
|
124
128
|
|
|
125
129
|
### Records
|
|
126
130
|
One store engine, two kinds of view. ``from_numpy`` writes a **dense** store
|
|
@@ -131,19 +135,19 @@ per-record metadata is touched:
|
|
|
131
135
|
```python
|
|
132
136
|
import numpy as np
|
|
133
137
|
from loaderx.utils import from_numpy
|
|
134
|
-
from loaderx.
|
|
138
|
+
from loaderx.zrecord import DenseStore
|
|
135
139
|
|
|
136
140
|
from_numpy('data', np.arange(64, dtype=np.float32).reshape(8, 2, 4))
|
|
137
|
-
ds =
|
|
141
|
+
ds = DenseStore('data')
|
|
138
142
|
ds[0, 5, 2] # (3, 2, 4) — a record set, shape straight from the schema
|
|
139
143
|
```
|
|
140
144
|
|
|
141
|
-
A
|
|
145
|
+
A store is a collection of records, not an ndarray, so ``ds[0, 5, 2]`` is a
|
|
142
146
|
record set — never ``ds[0][5][2]``. A scalar selects one record; negatives wrap
|
|
143
147
|
from the end. The ragged example below reads the same way.
|
|
144
148
|
|
|
145
149
|
``from_iterator`` writes a **ragged** store of variable-length records. It is a
|
|
146
|
-
separate contract: :class:`
|
|
150
|
+
separate contract: :class:`RaggedStore` hands back a list of arrays, so a
|
|
147
151
|
loader never has to carry ``row_splits`` around. ``dtype`` is unified and
|
|
148
152
|
explicit; each record keeps its **own shape**, recorded per record as it is
|
|
149
153
|
written and restored exactly on read — so records may differ in shape
|
|
@@ -153,11 +157,11 @@ batch is the model's call — a plain numpy loop, wherever you need it:
|
|
|
153
157
|
|
|
154
158
|
```python
|
|
155
159
|
from loaderx.utils import from_iterator
|
|
156
|
-
from loaderx.
|
|
160
|
+
from loaderx.zrecord import RaggedStore
|
|
157
161
|
|
|
158
162
|
seqs = [np.arange(L, dtype=np.int32) for L in (3, 1, 4, 1, 5)]
|
|
159
163
|
from_iterator('tokens', seqs, np.int32) # dtype explicit; each record keeps its shape
|
|
160
|
-
rs =
|
|
164
|
+
rs = RaggedStore('tokens')
|
|
161
165
|
|
|
162
166
|
records = rs[0, 2, 4] # list of ndarray — one per record, exact shapes
|
|
163
167
|
lengths = np.array([len(r) for r in records])
|
|
@@ -177,21 +181,21 @@ loader = DataLoader({'tokens': dense_tokens, 'label': labelset}, batch_size=32,
|
|
|
177
181
|
transform=collate)
|
|
178
182
|
```
|
|
179
183
|
|
|
180
|
-
### Writable
|
|
184
|
+
### Writable stores
|
|
181
185
|
|
|
182
|
-
The
|
|
186
|
+
The Store classes are loaderx's public persistence API: they are
|
|
183
187
|
read-write, and ``append`` is explicit — one container of records, one batch,
|
|
184
188
|
one native call. Nothing is buffered, inferred, or compressed for you.
|
|
185
189
|
|
|
186
190
|
```python
|
|
187
|
-
from loaderx.
|
|
191
|
+
from loaderx.zrecord import DenseStore, RaggedStore
|
|
188
192
|
|
|
189
|
-
ds =
|
|
193
|
+
ds = DenseStore('mnist/x', dtype=np.uint8, item_shape=(28, 28)) # schema written now
|
|
190
194
|
ds.append(images[i:i + 1024]) # (B, 28, 28) → one batch, returns first index
|
|
191
195
|
ds.append(single_image[None]) # one sample is batch_size 1 — add the axis yourself
|
|
192
196
|
ds[:4] # read path is unchanged
|
|
193
197
|
|
|
194
|
-
tok =
|
|
198
|
+
tok = RaggedStore('tokens', dtype=np.int32) # each record keeps its own shape
|
|
195
199
|
tok.append([seq_a, seq_b, seq_c]) # list in, list out — `tok[0, 2]` returns a list
|
|
196
200
|
```
|
|
197
201
|
|
|
@@ -227,7 +231,7 @@ a large win for many small, similar records (image tiles, token sequences).
|
|
|
227
231
|
The dictionary's cost is a cache footprint: every record's decompression
|
|
228
232
|
references the shared dictionary window, so a larger dictionary means more
|
|
229
233
|
cache misses on gather — the path a loader pays forever. Three named tiers
|
|
230
|
-
(`loaderx.
|
|
234
|
+
(`loaderx.zrecord.DICT_TIERS`) preset the whole tradeoff — the dictionary size
|
|
231
235
|
and how much data trains it — so a caller picks a tier, never a number:
|
|
232
236
|
|
|
233
237
|
| tier | dict | sample | tradeoff |
|
|
@@ -250,7 +254,7 @@ reader threads.
|
|
|
250
254
|
|
|
251
255
|
A dictionary must train on the settled, complete data. :func:`train_dict` is the
|
|
252
256
|
standalone, **manual** training step — a numpy array, an iterable of records, or
|
|
253
|
-
a
|
|
257
|
+
a typed store all train the same way, sized by a tier — and its bytes are handed to
|
|
254
258
|
a store-writing path via ``dict_bytes``. ``zstd_dict`` never trains by itself: a
|
|
255
259
|
write without a dictionary is an error. A stream cannot train its own
|
|
256
260
|
dictionary, but it can write with one trained on the settled data:
|
|
@@ -269,15 +273,15 @@ from_numpy('data', data, codec='zstd_dict', dict_bytes=d)
|
|
|
269
273
|
Changing an existing store's codec is a rewrite, not a store mutation: create a
|
|
270
274
|
new store with the new codec and copy the records in index order. Index order is
|
|
271
275
|
what keeps multi-stream alignment, and the copy loop is a few lines with the
|
|
272
|
-
|
|
276
|
+
Store layer — which is why no dedicated ``recode`` path exists:
|
|
273
277
|
|
|
274
278
|
```python
|
|
275
279
|
from loaderx.utils import train_dict
|
|
276
|
-
from loaderx.
|
|
280
|
+
from loaderx.zrecord import DenseStore
|
|
277
281
|
|
|
278
282
|
CHUNK = 1 << 16
|
|
279
|
-
with
|
|
280
|
-
|
|
283
|
+
with DenseStore("src") as s, \
|
|
284
|
+
DenseStore("dst", dtype=s.dtype, item_shape=s.item_shape,
|
|
281
285
|
codec="zstd_dict") as d:
|
|
282
286
|
if not d.has_dict(): # zstd_dict needs a dictionary
|
|
283
287
|
d._store.install_dict(train_dict(s)) # train one on the source store
|
|
@@ -285,7 +289,7 @@ with DenseDataset("src") as s, \
|
|
|
285
289
|
d.append(s[start:start + CHUNK]) # records copied in index order
|
|
286
290
|
```
|
|
287
291
|
|
|
288
|
-
``
|
|
292
|
+
``RaggedStore`` is the same shape — swap the constructors and ``dtype`` is all
|
|
289
293
|
the destination needs. ``dst`` must not already hold a store.
|
|
290
294
|
|
|
291
295
|
**Important:** Do not use `"zstd_dict"` while data is still changing (through
|
|
@@ -293,11 +297,11 @@ deletes or compaction below the Python layer). The dictionary captures a snapsho
|
|
|
293
297
|
of the data; training it before the data settles wastes compression. Train the
|
|
294
298
|
dictionary once preprocessing is complete and the content is final.
|
|
295
299
|
|
|
296
|
-
### Multi-stream
|
|
300
|
+
### Multi-stream stores (MultiStore)
|
|
297
301
|
|
|
298
302
|
A zrecord store is one stream; a training sample is usually several streams
|
|
299
|
-
(skeleton + label + id, tokens + label, ...). A multi-
|
|
300
|
-
directory whose immediate children are stores. `
|
|
303
|
+
(skeleton + label + id, tokens + label, ...). A multi-store is just a
|
|
304
|
+
directory whose immediate children are stores. `MultiStore` wraps them and
|
|
301
305
|
guarantees the one thing that matters: **index alignment** — record `i` lines
|
|
302
306
|
up across every stream, `append` writes every stream at the same indices,
|
|
303
307
|
`delete` removes the same indices from every stream, so alignment survives. No
|
|
@@ -305,7 +309,7 @@ new storage format, no manifest, no bundle-level batch API.
|
|
|
305
309
|
|
|
306
310
|
```python
|
|
307
311
|
from loaderx.utils import from_numpy, from_iterator
|
|
308
|
-
from loaderx.
|
|
312
|
+
from loaderx.zrecord import MultiStore
|
|
309
313
|
from loaderx.dataloader import DataLoader
|
|
310
314
|
|
|
311
315
|
root = "xsub/train"
|
|
@@ -313,7 +317,7 @@ from_numpy(root + "/joint", joint) # the streams are ordinary zrecord stores
|
|
|
313
317
|
from_numpy(root + "/label", label)
|
|
314
318
|
from_iterator(root + "/token", iter(seqs), np.int32)
|
|
315
319
|
|
|
316
|
-
ds =
|
|
320
|
+
ds = MultiStore(root) # wrap + verify they hold the same count
|
|
317
321
|
ds["joint"][0, 5, 2] # the stream's own index forms apply
|
|
318
322
|
ds.append({"joint": b, "label": l}) # same batch size, all streams, once
|
|
319
323
|
ds.delete([0, 5]) # same indices, all streams, still aligned
|
|
@@ -322,8 +326,8 @@ loader = DataLoader(ds.streams, batch_size=256) # hand the streams to a loader
|
|
|
322
326
|
batch = next(loader) # {name: values}, index-aligned
|
|
323
327
|
```
|
|
324
328
|
|
|
325
|
-
Equal-length and variable-length are both just stores — `
|
|
326
|
-
fixed-shape record per sample) and `
|
|
329
|
+
Equal-length and variable-length are both just stores — `DenseStore` (one
|
|
330
|
+
fixed-shape record per sample) and `RaggedStore` (variable row count per
|
|
327
331
|
record). The loader does not interpret either: it fetches by index and packs a
|
|
328
332
|
dict, so a dense stream's batch value is the stacked `(B, *item_shape)` array
|
|
329
333
|
and a ragged stream's is a list of per-record arrays. No padding is imposed —
|
|
@@ -384,26 +388,27 @@ For practical integration examples, please refer to the **[Data2Latent](https://
|
|
|
384
388
|
`scripts/bench.py` measures zrecord and loaderx against the alternatives in
|
|
385
389
|
the index sampler, the record store, and the full data loader — each through the
|
|
386
390
|
binding a client actually uses, so cffi, the GIL and the NumPy allocation are all
|
|
387
|
-
inside the timings.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
first — in under half a minute. Warm page cache.
|
|
391
|
+
inside the timings. This is a qualitative horizontal comparison, sized to a
|
|
392
|
+
realistic image workload (625 MiB of 256 KiB records). `python3 scripts/bench.py all`
|
|
393
|
+
prints the machine block first and then runs the default tables. Warm page cache.
|
|
391
394
|
|
|
392
|
-
**Machine** — one
|
|
393
|
-
|
|
395
|
+
**Machine** — one local workstation (AMD Ryzen AI 9 HX PRO 370, 12 cores / 24
|
|
396
|
+
threads):
|
|
394
397
|
|
|
395
398
|
| machine | value |
|
|
396
399
|
|-----------|-------|
|
|
397
|
-
| CPU | AMD
|
|
398
|
-
| frequency |
|
|
399
|
-
| caches | L1d
|
|
400
|
-
| NUMA |
|
|
401
|
-
| memory |
|
|
402
|
-
|
|
|
403
|
-
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
400
|
+
| CPU | AMD Ryzen AI 9 HX PRO 370 w/ Radeon 890M, 1 socket, 12 cores / 24 threads |
|
|
401
|
+
| frequency | 605–5158 MHz |
|
|
402
|
+
| caches | L1d 576 KiB, L1i 384 KiB, L2 12 MiB, L3 24 MiB |
|
|
403
|
+
| NUMA | 1 node |
|
|
404
|
+
| memory | 31 GiB (not limited by cgroup) |
|
|
405
|
+
| shared memory | 16 GiB `/dev/shm` |
|
|
406
|
+
| OS | Debian GNU/Linux forky/sid, kernel 7.1.3+deb13-amd64, x86_64 |
|
|
407
|
+
| python | 3.14.7, numpy 2.5.2 |
|
|
408
|
+
|
|
409
|
+
The benchmark process sees all 24 threads and is not memory-limited by cgroup.
|
|
410
|
+
The 16 GiB shared-memory mount accommodates the four-worker, 64 MiB-batch torch
|
|
411
|
+
pipeline. Store reads run on the ordinary page cache.
|
|
407
412
|
|
|
408
413
|
**1. Sampler** — index generation on its own, IID (with replacement), 1M index
|
|
409
414
|
space, against NumPy's modern API. The µs-scale figures fluctuate with box load;
|
|
@@ -411,12 +416,12 @@ the stable signal is the ~1.9x margin, roughly flat across batch sizes.
|
|
|
411
416
|
|
|
412
417
|
| sampler | batch | per batch | vs default_rng |
|
|
413
418
|
|-------------------|-------|-----------|----------------|
|
|
414
|
-
| numpy default_rng | 256 |
|
|
415
|
-
| **zsampler** | 256 |
|
|
416
|
-
| numpy default_rng | 1024 |
|
|
417
|
-
| **zsampler** | 1024 |
|
|
418
|
-
| numpy default_rng | 8192 |
|
|
419
|
-
| **zsampler** | 8192 |
|
|
419
|
+
| numpy default_rng | 256 | 3.8 µs | 1.00x |
|
|
420
|
+
| **zsampler** | 256 | 2.0 µs | **1.92x** |
|
|
421
|
+
| numpy default_rng | 1024 | 5.1 µs | 1.00x |
|
|
422
|
+
| **zsampler** | 1024 | 2.8 µs | **1.84x** |
|
|
423
|
+
| numpy default_rng | 8192 | 20.4 µs | 1.00x |
|
|
424
|
+
| **zsampler** | 8192 | 10.0 µs | **2.03x** |
|
|
420
425
|
|
|
421
426
|
**2. Store** — Zrecord against the alternatives: random batch gather, 2500
|
|
422
427
|
records, batch 256, structured (mildly compressible) data. A single 256 KiB
|
|
@@ -428,34 +433,32 @@ Realistic records — 256 KiB per record, 64 MiB per batch:
|
|
|
428
433
|
|
|
429
434
|
| store | write | gather | on disk | ratio |
|
|
430
435
|
|-------------------|------------|-------------|---------|-------|
|
|
431
|
-
| zrecord-zstd |
|
|
432
|
-
| zrecord-zstdict |
|
|
433
|
-
| zrecord-raw |
|
|
434
|
-
| npy-mmap |
|
|
435
|
-
| hdf5 |
|
|
436
|
-
| hdf5-gzip |
|
|
437
|
-
| blosc2 |
|
|
438
|
-
| tensorstore |
|
|
439
|
-
| arrayrecord |
|
|
436
|
+
| zrecord-zstd | 816 MiB/s | 4603 MiB/s | 555 MiB | 1.13x |
|
|
437
|
+
| zrecord-zstdict | 43 MiB/s | 2017 MiB/s | 388 MiB | 1.61x |
|
|
438
|
+
| zrecord-raw | 1990 MiB/s | 8803 MiB/s | 625 MiB | 1.00x |
|
|
439
|
+
| npy-mmap | 2686 MiB/s | 4408 MiB/s | 625 MiB | 1.00x |
|
|
440
|
+
| hdf5 | 2559 MiB/s | 2288 MiB/s | 625 MiB | 1.00x |
|
|
441
|
+
| hdf5-gzip | 51 MiB/s | 237 MiB/s | 445 MiB | 1.40x |
|
|
442
|
+
| blosc2 | 73 MiB/s | 646 MiB/s | 536 MiB | 1.17x |
|
|
443
|
+
| tensorstore | 397 MiB/s | 299 MiB/s | 462 MiB | 1.35x |
|
|
444
|
+
| arrayrecord | 518 MiB/s | 1602 MiB/s | 567 MiB | 1.10x |
|
|
440
445
|
|
|
441
446
|
`write` is page-cache ingestion — the store is built and left open, exactly
|
|
442
447
|
like `np.save` and the other backends, which defer durability to the kernel.
|
|
443
448
|
A zrecord is append-only, so this is one pass over the frontier; at 256 KiB
|
|
444
|
-
records the 16-byte table entry per record is negligible
|
|
445
|
-
|
|
449
|
+
records the 16-byte table entry per record is negligible. Durability is the
|
|
450
|
+
explicit `sync()`/`close` — earlier `write` numbers
|
|
446
451
|
included zrecord's close-time `fsync` while the competition did not, which
|
|
447
452
|
compared durable writes against lazy ones. The absolute `write` figures
|
|
448
|
-
fluctuate with
|
|
449
|
-
`.npy` is the stable part.
|
|
453
|
+
fluctuate with machine load and should be treated as ballpark figures.
|
|
450
454
|
|
|
451
455
|
`gather` is fully page-cache-warmed — the benchmark sweeps every record once
|
|
452
456
|
before timing, so it measures the pure access path (memory), not first-touch
|
|
453
457
|
page faults or disk. At 256 KiB records the batch (64 MiB) exceeds L3, so these
|
|
454
|
-
numbers are DRAM-bandwidth-bound for every backend
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
single-threaded copy is slower.
|
|
458
|
+
numbers are DRAM-bandwidth-bound for every backend. Fully warm, zrecord-raw
|
|
459
|
+
leads npy-mmap by 2.0x on this box — its gather fans out across every core while
|
|
460
|
+
numpy's fancy index is single-threaded. Plain zstd reaches 4.6 GiB/s, 7.1x the
|
|
461
|
+
next compressed contender at a similar ratio (blosc2).
|
|
459
462
|
|
|
460
463
|
**3. Loader** — the full input pipeline end to end (sample, fetch, collate, hand
|
|
461
464
|
over a batch), same workload, 4 workers, batch 256 (64 MiB). The `peak RSS`
|
|
@@ -466,62 +469,68 @@ at the full batch.
|
|
|
466
469
|
|
|
467
470
|
| loader | batches/s | peak RSS |
|
|
468
471
|
|----------------|-----------|----------|
|
|
469
|
-
| **loaderx** |
|
|
470
|
-
| loaderx-raw |
|
|
471
|
-
| torch |
|
|
472
|
-
| grain |
|
|
472
|
+
| **loaderx** | 72.2 | 2794 MiB |
|
|
473
|
+
| loaderx-raw | 136.7 | 2805 MiB |
|
|
474
|
+
| torch | 66.7 | 16047 MiB |
|
|
475
|
+
| grain | 16.9 | 4803 MiB |
|
|
473
476
|
|
|
474
477
|
At 64 MiB per batch the loader is DRAM-bound, not sampler-bound — the per-batch
|
|
475
|
-
gather (zstd ~
|
|
478
|
+
gather (zstd ~4.6 GiB/s, raw ~8.6 GiB/s) is the whole story, and the prefetch
|
|
476
479
|
threads keep it at store-gather speed while the Python side collates. The
|
|
477
|
-
memory is the prefetch buffers plus the two
|
|
480
|
+
memory is the prefetch buffers plus the two Store handles (raw + label stores
|
|
478
481
|
over the same backing data). loaderx prefetches in threads inside one process,
|
|
479
482
|
so workers share one interpreter, one numpy and one set of gather buffers; torch
|
|
480
483
|
and grain run a worker process per prefetch thread, which is most of their RSS
|
|
481
|
-
(torch's peak also includes the shared-memory collated batches).
|
|
482
|
-
|
|
484
|
+
(torch's peak also includes the shared-memory collated batches). Compressed
|
|
485
|
+
loaderx is slightly ahead of torch; loaderx-raw is 2.0x faster than torch and
|
|
486
|
+
8.1x faster than grain.
|
|
483
487
|
|
|
484
488
|
**Free-threaded Python.** loaderx targets free-threaded builds (no GIL), and
|
|
485
489
|
the key sections are also measured on 3.14t — the question is whether anything
|
|
486
490
|
gains when nothing is GIL-limited. These are opt-in runs (a second interpreter
|
|
487
491
|
and `--transform augment`); they are not part of the default `all`:
|
|
488
492
|
|
|
489
|
-
* **Sampler** — zsampler draws ~1.9–2x faster than free-threaded numpy
|
|
490
|
-
same margin as on the GIL build: a
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
`zrecord-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
493
|
+
* **Sampler** — zsampler draws ~1.9–2x faster than free-threaded numpy (the
|
|
494
|
+
256-row run was a noisy 2.46x), the same broad margin as on the GIL build: a
|
|
495
|
+
batch is one Zig call either way.
|
|
496
|
+
* **Store** — the free-threaded numbers track the GIL table closely.
|
|
497
|
+
`zrecord-raw` gathers 8.9 vs 8.8 GiB/s and `zrecord-zstd` 4.7 vs 4.6 GiB/s.
|
|
498
|
+
The no-GIL table was run without blosc2 so its import could not change the
|
|
499
|
+
process mode. blosc2 was measured separately at 678 MiB/s; its extension
|
|
500
|
+
emits a warning and re-enables the GIL, so that cell is not a no-GIL result.
|
|
501
|
+
ArrayRecord has no usable 3.14t extension. Random gather, 256 KiB records:
|
|
497
502
|
|
|
498
503
|
| store | CPython 3.14 (GIL) | free-threaded 3.14t |
|
|
499
504
|
|--------------|--------------------|---------------------|
|
|
500
|
-
| zrecord-raw |
|
|
501
|
-
| zrecord-zstd |
|
|
502
|
-
| npy-mmap |
|
|
503
|
-
| hdf5 |
|
|
504
|
-
| blosc2 |
|
|
505
|
-
| tensorstore |
|
|
506
|
-
* **Loader, identity** — unchanged
|
|
507
|
-
|
|
505
|
+
| zrecord-raw | 8803 MiB/s | 8878 MiB/s |
|
|
506
|
+
| zrecord-zstd | 4603 MiB/s | 4707 MiB/s |
|
|
507
|
+
| npy-mmap | 4408 MiB/s | 3974 MiB/s |
|
|
508
|
+
| hdf5 | 2288 MiB/s | 2210 MiB/s |
|
|
509
|
+
| blosc2 | 646 MiB/s | 678 MiB/s (GIL enabled) |
|
|
510
|
+
| tensorstore | 299 MiB/s | 323 MiB/s |
|
|
511
|
+
* **Loader, identity** — unchanged on both interpreters at 64 MiB per batch:
|
|
512
|
+
|
|
513
|
+
| loader | CPython 3.14 (GIL) | free-threaded 3.14t |
|
|
514
|
+
|-------------|--------------------|---------------------|
|
|
515
|
+
| loaderx | 72.2 batches/s | 71.1 batches/s |
|
|
516
|
+
| loaderx-raw | 136.7 batches/s | 136.0 batches/s |
|
|
508
517
|
* **Loader, CPU-heavy transform** — the one place the free-threaded build
|
|
509
518
|
matters. A transform runs on the prefetch threads, so the GIL serializes it on
|
|
510
519
|
standard CPython — the case where worker processes win, and the reason for the
|
|
511
520
|
free-threaded build. `--transform augment` (a Python-bound per-sample loop),
|
|
512
|
-
4 workers
|
|
513
|
-
|
|
521
|
+
4 workers. Torch and Grain have no free-threaded rows, so their GIL worker
|
|
522
|
+
processes are shown only as context:
|
|
514
523
|
|
|
515
524
|
| loader | CPython 3.14 (GIL) | free-threaded 3.14t |
|
|
516
525
|
|-----------------|--------------------|---------------------|
|
|
517
|
-
| **loaderx** |
|
|
518
|
-
| loaderx-raw |
|
|
526
|
+
| **loaderx** | 33.1 batches/s | 41.9 batches/s |
|
|
527
|
+
| loaderx-raw | 36.4 batches/s | 51.9 batches/s |
|
|
528
|
+
| torch | 35.9 batches/s | — |
|
|
529
|
+
| grain | 10.2 batches/s | — |
|
|
519
530
|
|
|
520
|
-
Free-threaded
|
|
521
|
-
threads
|
|
522
|
-
|
|
523
|
-
was the whole cost) because the 64 MiB gather is DRAM-bound, but wider than
|
|
524
|
-
at the 768 KiB scale, where the pipeline was even more DRAM-bound.
|
|
531
|
+
Free-threaded wins because the transform parallelizes across the prefetch
|
|
532
|
+
threads: 1.27x on loaderx and 1.43x on raw at 256 KiB. The margin is bounded
|
|
533
|
+
by the 64 MiB gather, which remains DRAM-bandwidth-heavy.
|
|
525
534
|
|
|
526
535
|
**Conclusion** — why the numbers look like this.
|
|
527
536
|
|
|
@@ -547,15 +556,16 @@ on the multi-core memory subsystem that closes the gap to an uncompressed
|
|
|
547
556
|
**Compression is in the kernel, and there is one codec.** `zrecord-zstd` is not
|
|
548
557
|
"storage plus a codec": the layout, the multi-core decompress and the GIL-free
|
|
549
558
|
copy are one path, so turning compression on costs part of a margin, not an
|
|
550
|
-
order of magnitude — ~
|
|
551
|
-
|
|
559
|
+
order of magnitude — ~4.6 GiB/s here, ~7.1x ahead of the next compressed store
|
|
560
|
+
at a similar ratio. The modest ratio is the data, not the
|
|
552
561
|
format: these samples are barely compressible, and on a smooth image set plain
|
|
553
562
|
zstd reaches 7.6x and the dictionary (at the `"max"` tier) 16.5x.
|
|
554
563
|
|
|
555
564
|
**The loader gap is architecture, not storage.** loaderx uses threads and never
|
|
556
565
|
ends an epoch, so a step pays no IPC and never waits on an epoch boundary; torch
|
|
557
|
-
restarts per epoch with worker processes.
|
|
558
|
-
and
|
|
566
|
+
restarts per epoch with worker processes. Here compressed loaderx is 1.1x faster
|
|
567
|
+
than torch and 4.3x faster than grain; raw loaderx is 2.0x and 8.1x faster,
|
|
568
|
+
respectively. Storage also differs per loader — each reads from
|
|
559
569
|
what it was built for — so the loader table is a different comparison than the
|
|
560
570
|
store table, not a rerun of it.
|
|
561
571
|
The one crack in the thread model is a CPU-heavy transform, which the GIL
|
|
@@ -570,23 +580,24 @@ page-cache ingestion with durability deferred, matching the other backends —
|
|
|
570
580
|
zrecord's own durability (`sync`/`close`) is a separate, explicit cost that
|
|
571
581
|
neither this table nor the competition pays. This is a single qualitative pass —
|
|
572
582
|
the µs-scale sampler timings and the loader `batches/s` fluctuate with box load
|
|
573
|
-
(on these
|
|
583
|
+
(on these 12 cores the compressed loader trails the raw one substantially), so
|
|
574
584
|
treat the absolute numbers as ballpark and the cross-backend margins as the
|
|
575
585
|
signal.
|
|
576
586
|
|
|
577
587
|
## Real-data verification: NTU RGB-D skeletons
|
|
578
588
|
|
|
579
|
-
The tables above are synthetic workloads. As a ground-truth check,
|
|
580
|
-
run end to end on **NTU RGB-D skeleton data** — 114,480 raw `.skeleton` files,
|
|
589
|
+
The tables above are synthetic workloads. As a historical ground-truth check,
|
|
590
|
+
loaderx was run end to end on **NTU RGB-D skeleton data** — 114,480 raw `.skeleton` files,
|
|
581
591
|
120 action classes, 25 joints — processed into the ST-GCN `N C T V M` layout
|
|
582
592
|
(per-sample `(3, 300, 25, 2)` float32) for the `xsub`/`xview` protocols. The
|
|
583
593
|
`.npy` outputs of the standard preprocessing pipeline were treated as ground
|
|
584
|
-
truth
|
|
594
|
+
truth. This verification was not rerun with the synthetic benchmarks above;
|
|
595
|
+
its throughput is retained as a separate historical 12-core result.
|
|
585
596
|
|
|
586
597
|
**Correctness — the read path is bit-exact against the ground truth:**
|
|
587
598
|
|
|
588
599
|
* Full scan of all **228,356 records** (joint float32 + label int64, all four
|
|
589
|
-
splits) through `
|
|
600
|
+
splits) through `DenseStore`: byte-for-byte identical to the reference npy.
|
|
590
601
|
* A `DataLoader` over joint + label + an index stream, run under all three
|
|
591
602
|
sampler modes (`sequential`, `iid`, `cyclic`): every received batch is
|
|
592
603
|
bit-exact to the ground truth at its own declared indices, and the streams
|
|
@@ -621,7 +632,7 @@ the same split).
|
|
|
621
632
|
|
|
622
633
|
**The npy intermediate is optional.** `from_numpy` is chunked append under the
|
|
623
634
|
hood, so the whole npy staging step can be skipped: parse the skeleton files in
|
|
624
|
-
parallel and feed `
|
|
635
|
+
parallel and feed `DenseStore.append` the fixed-shape chunks directly. This
|
|
625
636
|
writes the store in one pass (no npy, no second read), and the resulting store
|
|
626
637
|
is byte-for-byte the same size as the `from_numpy` equivalent — verified record
|
|
627
638
|
by record against the npy ground truth.
|
|
@@ -676,6 +687,13 @@ Index Generator: a high-performance sampler implemented in Zig. Every mode is a
|
|
|
676
687
|
pure function of `(seed, step)`, so a run resumes exactly by seeking to a step —
|
|
677
688
|
there is no epoch to track, in keeping with the endless step-based loader.
|
|
678
689
|
|
|
690
|
+
```python
|
|
691
|
+
from loaderx.zsampler import Sampler
|
|
692
|
+
|
|
693
|
+
sampler = Sampler(1_000_000, 256, Sampler.Mode.IID, seed=42)
|
|
694
|
+
indices = sampler.next()
|
|
695
|
+
```
|
|
696
|
+
|
|
679
697
|
1. **Sequential** — traverse the index space in order through a fixed-size sliding
|
|
680
698
|
window, treating the space as a circular queue so the tail never truncates.
|
|
681
699
|
2. **IID** — draw each index uniformly at random with replacement. Unbiased
|
|
@@ -696,25 +714,27 @@ there is no epoch to track, in keeping with the endless step-based loader.
|
|
|
696
714
|
---
|
|
697
715
|
|
|
698
716
|
# Zrecord
|
|
699
|
-
|
|
717
|
+
Zrecord is loaderx's typed persistent record store. Its private native runtime is
|
|
718
|
+
the byte-oriented engine beneath the public `DenseStore` and `RaggedStore` contracts.
|
|
700
719
|
|
|
701
|
-
1.
|
|
720
|
+
1. The engine is an unordered physical store made of N records. Records are
|
|
702
721
|
independent and carry no ordering, so every index and slice operation is
|
|
703
722
|
equivalent to a gather.
|
|
704
|
-
2.
|
|
723
|
+
2. It hands the Store layer a dense index space: the live records are always
|
|
705
724
|
exactly `0..N`. Deletion preserves that by swapping the tail into the hole,
|
|
706
725
|
which means an index is stable only until something is deleted. A
|
|
707
|
-
multi-stream
|
|
726
|
+
multi-stream store is purely a Python-layer notion; `MultiStore` keeps its
|
|
708
727
|
own stream index table pointing at records.
|
|
709
|
-
3.
|
|
728
|
+
3. The engine reads and writes byte ranges. `DenseStore` and `RaggedStore` own
|
|
729
|
+
dtype, shape, allocation and return-value semantics.
|
|
710
730
|
4. The IO model (`append | read | delete`) is batch-oriented and
|
|
711
731
|
shape-agnostic. A record is a packed byte range located by an offset; there
|
|
712
732
|
is no notion of fixed vs variable length, and a single-record operation is
|
|
713
733
|
just the `batch_size == 1` case. Equal length and single records are
|
|
714
734
|
special cases, not parallel code paths.
|
|
715
|
-
5.
|
|
735
|
+
5. The engine owns its temporary memory internally — allocation and release are explicit.
|
|
716
736
|
6. A store has exactly **one** codec, fixed at creation and immutable
|
|
717
|
-
|
|
737
|
+
afterwards — matching the Store semantics above it, where the schema
|
|
718
738
|
records a single `codec`. Every record is compressed and decompressed
|
|
719
739
|
independently:
|
|
720
740
|
|
|
@@ -750,7 +770,7 @@ A record-based data runtime, focused on delivering extreme throughput and low la
|
|
|
750
770
|
`zstd` store never touches a dictionary even if one is present.
|
|
751
771
|
|
|
752
772
|
## Persistence format
|
|
753
|
-
|
|
773
|
+
Native storage is metadata plus chunked data. The extension is the type:
|
|
754
774
|
`.zr` files are store-global singletons, `.loc` files are record-table segments,
|
|
755
775
|
`.chunk` files are record data:
|
|
756
776
|
```
|
|
@@ -775,12 +795,13 @@ byte), so the packed header reads as plain memory.
|
|
|
775
795
|
The record table is partitioned into `{id}.loc` segments so it can **grow by
|
|
776
796
|
appending a segment** instead of reserving the maximum. The id→segment mapping
|
|
777
797
|
is pure arithmetic — `seg = idx >> 28`, `off = (idx & (2^28−1)) × 16` — so a
|
|
778
|
-
segment needs no per-record bookkeeping.
|
|
779
|
-
|
|
798
|
+
segment needs no per-record bookkeeping. Committed entries are immutable; one
|
|
799
|
+
shared fd-table lock keeps the in-memory ArrayList stable while readers index it
|
|
800
|
+
during the rare append that adds another segment.
|
|
780
801
|
|
|
781
802
|
**1. Header** — 32 bytes, the whole of meta.zr.
|
|
782
803
|
* `magic` (`ZREC`) and `version` are ordinary fields, so opening a directory
|
|
783
|
-
that is not a
|
|
804
|
+
that is not a loaderx store fails immediately instead of decoding garbage.
|
|
784
805
|
* `codec` is the store's one compression method, stamped at creation and
|
|
785
806
|
immutable — there is no per-record tag anywhere.
|
|
786
807
|
* `length` (u64) is the total number of records | `tail_chunk`/`tail_offset`
|
|
@@ -825,10 +846,11 @@ against. The real bounds are the field widths — 2^32 chunks of 2^32 bytes
|
|
|
825
846
|
|
|
826
847
|
**1. Write.** Writes are append-only; everything else is offset redirection.
|
|
827
848
|
* Append: compress concurrently → assign physical locations serially → flush
|
|
828
|
-
concurrently → commit metadata.
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
over to a
|
|
849
|
+
concurrently → commit metadata. Append publishes through the page cache and
|
|
850
|
+
is intentionally lazy; `sync()` makes the committed frontier durable in
|
|
851
|
+
payload → record-table → header order and propagates any sync failure. A
|
|
852
|
+
record never straddles two chunks; one that would not fit rolls over to a
|
|
853
|
+
fresh chunk.
|
|
832
854
|
* **Flush granularity is the store's, not the caller's.** The batch size a
|
|
833
855
|
client passes to `append` bounds memory only; zrecord's flush stage packs
|
|
834
856
|
a shard's contiguous records into `pwritev`s capped at 256 KiB (`flush_bytes`).
|
|
@@ -850,14 +872,15 @@ against. The real bounds are the field widths — 2^32 chunks of 2^32 bytes
|
|
|
850
872
|
|
|
851
873
|
**2. Read.** Fill the destination memory concurrently, in place from the Python
|
|
852
874
|
side (executed on async threads).
|
|
853
|
-
* Committed records are immutable
|
|
854
|
-
|
|
875
|
+
* Committed records are immutable and `length` is published through an atomic.
|
|
876
|
+
A gather takes one shared fd-table lock so a rare chunk/segment ArrayList
|
|
877
|
+
growth cannot invalidate its file handles; record I/O itself stays lock free.
|
|
855
878
|
* Every record is read at the offset its table entry records — the record table
|
|
856
879
|
is addressed by pure arithmetic, so random access is one pread for the
|
|
857
880
|
location and one for the bytes, with no batching assumptions about layout.
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
per-shard staging buffer and
|
|
881
|
+
Each shard reads one location and immediately reads/decompresses that record;
|
|
882
|
+
there is no separate metadata phase or sequential-run special case. Compressed
|
|
883
|
+
records use a per-shard staging buffer and decode in place into the destination.
|
|
861
884
|
|
|
862
885
|
**3. Concurrency model.** `Io.Group.async` shards work by CPU count, and shards
|
|
863
886
|
beyond the limit run inline on the calling thread.
|
|
@@ -895,7 +918,7 @@ is reclaimed by an offline `compact` that rewrites the live records in place.
|
|
|
895
918
|
`readPositionalAll`/`writePositionalAll`.
|
|
896
919
|
|
|
897
920
|
**Concurrency contract.** `gather` and `append` are safe to call concurrently
|
|
898
|
-
from many threads.
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
921
|
+
from many threads. Append remains single-writer; only rare chunk/segment fd-table
|
|
922
|
+
growth briefly waits for active gathers. `delete` and `compact` mutate the table
|
|
923
|
+
in ways a reader would observe half-applied, so they require exclusive access to
|
|
924
|
+
the store.
|