Skip to content

Research notes / Scientific data access

HDF5 chunk cache: more memory does not fix every reread

Published 17 October 2026 / Updated 20 October 2026 / Measured library reads

Increasing an HDF5 chunk cache from 16 to 64 KiB did not remove a single reread in our one-slot test. Changing the slot count, or grouping the same selections by chunk, reduced 32 raw chunk reads to 4. This is a measured library-access result, not an eightfold speedup claim.

On this page9 sections

The same 128 bytes, two different read counts

The fixture contains a 64 by 64 array of unsigned 32-bit integers, split into four 32 by 32 chunks. Each chunk expands to 4,096 bytes; gzip level 6 stores each in 1,325 to 1,335 bytes in this build. We request eight different scalars from each chunk: 32 selections and 128 application bytes in total.

Round-robin order visits A, B, C, D eight times. Grouped order visits all eight selected values in A before B, C and D. The selected coordinates and values are identical as a set; only their order changes.

Raw chunk reads per 32 scalar selections. Linear scale, starting at zero.
  1. One slot32
  2. More bytes, one slot32
  3. Four chunks fit4
  4. Compressed size fits32
  5. One chunk fits32
  6. Grouped selections4
One repetition shown; all three repetitions agreed. Cache bytes exclude other library and application memory.
CaseCache KiBSlotsOrderChunk readsStored bytes read
One slot161round-robin3242,624
More bytes, one slot641round-robin3242,624
Four chunks fit1617round-robin45,328
Compressed size fits217round-robin3242,624
One chunk fits417round-robin3242,624
Grouped selections41grouped45,328

With 17 slots and 16 KiB, the first visit to each chunk reads its stored payload; subsequent visits need no additional raw chunk read. With one slot, four times as many cache bytes still gives 32 reads. With grouped selections, one slot and only 4 KiB achieves the same four reads as the larger cache.

The compression ratio is not the cache-capacity ratio. Our 2 KiB case can hold any compressed chunk's byte length, but cannot retain its 4 KiB decoded image. It reads a chunk on every selection. The 4 KiB round-robin case fits one decoded chunk but cannot retain the four-chunk reuse set.

Bytes, slots and reuse distance are separate constraints

An HDF5 chunked layout partitions an array into blocks; filters operate per chunk. A small selection from a filtered chunk can require processing that whole chunk. This is different from content-defined deduplication chunks. [4]

The raw-data chunk cache has a byte budget and a hash table. Colliding entries cannot coexist even when unused byte capacity remains. The HDF Group also documents changes to chunk-index calculation across versions; a layout-specific modulo calculation should not be treated as a permanent API contract. [2]

We deliberately use one slot to force the collision boundary without assuming a particular hash formula. Seventeen slots is a control that worked for these four chunks, not a recommended universal value. The experiment keeps the eviction parameter rdcc_w0 at zero throughout, so it does not compare eviction policies.

Cache parameters are per dataset. The h5py guide describes different default byte budgets before and after HDF5 2.0; record effective values instead of assuming that a historical default applies. In this experiment, each open dataset's access property list must match the requested settings or the runner stops. [3]

What the instrument sees, and what it does not

The entire HDF5 file lives in a Python memory buffer. A wrapper logs each read and readinto callback during every scalar selection. Chunk offsets and stored sizes come from get_chunk_info_by_coord, not from assumptions about adjacent chunks. The runner counts only exact matches and rejects ambiguous partial overlaps. Metadata reads remain in the trace but are excluded from raw-payload totals. [5]

Each case gets a fresh HDF5 open and an empty dataset cache. All returned integers are checked against the original array. We repeat six cases three times on one host: 18 controlled case runs, not 18 independent performance samples. Raw observations retain all 576 selections, driver reads, cache settings, environment and source hashes.

No physical disk is read by the observation path. The 42,624 versus 5,328 byte totals refer to stored chunk payload requested through the file driver. They exclude metadata, Python overhead and copying, and cannot be called SSD traffic, filesystem IOPS or elapsed-time improvement.

Multiplying chunk reads by 4,096 gives an inferred decoded volume of 131,072 versus 16,384 bytes. Dividing by 128 selected bytes gives 1,024 versus 128. These are arithmetic decode-volume ratios for this filtered scalar trace, not measured decompressor calls or a universal read-amplification factor. Even the cache-friendly case decodes substantially more data than the application selects.

A historical case study, with a different measurement boundary

The HDF Group's 2015 technical paper studies a satellite-data array with gzip-compressed chunks larger than its configured cache. Pages 16-19 compare cache enlargement, chunk-aligned access and rewriting with smaller chunks. The reported timings belong to that application and environment. We did not reproduce its data or benchmark; our smaller in-memory experiment isolates callback counts and deliberately separates collision pressure from byte capacity. [1]

The paper also describes per-dataset memory accumulation. Enlarging every cache is therefore a resource decision, not a free optimization. Its historical slot-default and indexing discussion should not substitute for the installed library's settings. [1]

A practical order for investigating rereads

  1. Record the array type, chunk dimensions, filters and exact selection trace. For fixed-width values, multiply dimensions by element size to obtain decoded chunk bytes.
  2. Find the set of chunks revisited before eviction. In our round-robin trace that set contains four chunks, not one.
  3. Check both byte capacity and slots. The one-slot control shows why increasing only bytes can have no effect.
  4. Try grouping or batching accesses when application ordering permits. Our grouped test preserves the selected values but would need reordering if a consumer requires the original sequence.
  5. Then measure the real application's latency, CPU cost and memory footprint on its real driver. Our callback counts alone cannot select a production cache size.

Changing the physical chunk layout requires a separate rewrite decision and validation of the resulting file. Faster reads do not establish application completeness or crash durability; those are covered in the HDF5 SWMR experiment.

A cache also carries the history of earlier reads

Enabling checks on the next read did not retroactively validate a cached chunk. In a separate HDF5 1.14.6 fixture, we changed one bit in a Fletcher32-protected chunk without updating its checksum. A permissive read returned the changed values. A subsequent strict read through the same dataset also returned them with a 1 MiB cache; a fresh file open rejected the unchanged stored bytes.

Both priming policies were explicitly selected: disable error detection (EDC), or install a callback returning H5Z_CB_CONT after checksum failure. The latter detected the failure but continued. Neither is the ordinary h5py read policy. The second read used a new transfer property list with EDC enabled and no failure callback. [Reader policy] [Pinned pipeline]

Four designed sequences, each repeated three times. Zero-cache and fresh-reader controls rejected the same damaged input.

Priming readCache bytesStrict same-dataset readStrict fresh-file read
EDC disabled1,048,576Changed valuesRead error
EDC disabled0Read errorRead error
Callback continues1,048,576Changed valuesRead error
Callback continues0Read errorRead error

The native cache-hit path reuses decoded data; a miss loads stored bytes through the filter pipeline. The effective budgets were read back from access properties, and file bytes were checked for equality before and after each sequence. This separates cache history from changing media or a repaired file. [HDF5 1.14.6 source]

Changing the conversion path is a separate correctness decision: HDF5 and NumPy integer casts returned different out-of-range values on two tested stacks. A fresh reader and a valid checksum do not recover integers already changed before writing.

Keep permissive salvage separate from acceptance verification. In this fixture, closing all handles and opening a fresh file restored rejection. Disabling caching is a diagnostic control, not a general performance recommendation; we do not prescribe refresh() as a universal integrity reset.

The reproducible dataset includes intact controls, all 24 fresh-reader policy observations and 12 cache sequences. This uses one-dimensional uint32 data, a single Fletcher32 filter and a memory-backed driver on h5py 3.15.0 / HDF5 1.14.6. It is not a cross-version, concurrency or hardware-failure result. The companion coverage table explains why a declared filter and zero chunk mask can also be insufficient.

Small compressed chunks can hide a large string heap

For variable-length strings, compressed chunk size can be a badly incomplete storage budget. In a separate fixture containing 611,328 text bytes, get_storage_size() reported 2,881 bytes with gzip enabled. The closed HDF5 file image occupied 658,974 bytes: about 229 times that raw-chunk total, and larger than the original text.

Variable-length string chunks contain descriptors for payload held in separate heaps. The HDF Group documents that dataset filters do not process these heaps; compression can shrink the descriptors without shrinking the strings. This is a representation boundary, not a failed compression request. [Heap/filter scope] [String layout]

The same 1,024 strings in three layouts, with and without gzip level 6. Lengths cycle through 256, 512 and 1,024 bytes; every byte is ASCII A. One repetition is shown; all three agreed. All sizes are bytes.

RepresentationCompressionRaw chunk storageComplete file image
Variable-length stringsnone16,384672,365
Variable-length stringsgzip-62,881658,974
Fixed-width stringsnone1,048,5761,049,197
Fixed-width stringsgzip-65,1215,870
Byte payload + offsetsnone623,104624,647
Byte payload + offsetsgzip-64,6866,873

Turning on gzip reduced the variable-length descriptor storage from 16,384 to 2,881 bytes, but reduced the complete file by only about 2%. Fixed-width strings compressed to a 5,870-byte file; a byte payload plus a separate offset array used 6,873 bytes. Those are results for highly repetitive text, not general compression ratios.

The content control keeps every string length unchanged but replaces A with deterministic hexadecimal SHA-256 text. Its compressed variable-length file still occupies 658,974 bytes, while fixed-width and offsets layouts grow to 368,598 and 357,298 bytes. Thus the ranking of those latter two layouts changes. Shorter-string controls and uncompressed cases are retained in the download, rather than selecting only the favorable case.

A different cache is involved

Koziol and Mainzer's 2019 design sketch explains that global-heap traffic uses the metadata cache and may evict other metadata. Its appendix compares native variable-length data with a flattened vector plus lengths. That is a prototype comparison, not evidence that the proposed redesign shipped. Our offsets layout is a separate size experiment, not a reproduction of those timing results. Increasing the raw chunk cache alone does not address every variable-length access cost. [Design sketch, pp. 1-6]

The HDF5 global heap definition distinguishes file-format storage from a process-memory heap and from the fractal heaps used for other HDF5 structures.

Keep the accounting boundaries explicit

H5Dget_storage_size reports allocated raw dataset storage; for filtered chunks it reports stored filtered bytes. It is not a complete-file or process-memory measurement. The runner independently sums allocated chunk sizes and checks that sum against the API result. [Size API]

The variable-length dataset's nbytes is 8,192 in this environment, reflecting 1,024 eight-byte NumPy object slots, not the 611,328 text bytes. The file-minus-chunks difference includes heaps, metadata and other file space; calling that difference exclusively heap overhead would also be wrong. These distinctions extend the fixed-width cache arithmetic above: an object-type element size does not describe all of its payload.

Fixed-width storage needs a validated maximum encoded byte length: h5py can silently truncate longer strings, including part of a multibyte character. The runner rejects over-width inputs before conversion. The offsets layout retains explicit record boundaries using a byte array and 64-bit offsets, but readers must validate monotonic offsets and the final endpoint, and coordinate updates to both datasets. It is not an automatic recommendation for mutable or concurrent data. [String contract]

Across 24 designed combinations repeated three times, all 72 fresh-file readbacks reconstruct every record exactly. This measures closed file-image lengths using h5py 3.15.0, HDF5 1.14.6, NumPy 2.3.3 and zlib 1.3, with v110/v110 format bounds. The different layouts use explicit, different chunk units. There is no throughput, peak-memory, random-access, checksum or crash-durability result.

Inspect the companion data and field definitions, including the full JSON, CSV, executable experiment and regression tests. Original code and generated observations are CC0-1.0.

Reproduce and inspect the trace

Download the runner, tests and pinned requirements together. The dataset page provides the CSV, complete JSON and field definitions. Original code and observations are CC0-1.0; upstream materials keep their licenses.

python3 -m venv .venv
.venv/bin/pip install --only-binary=:all: -r hdf5-chunk-cache-requirements.txt
.venv/bin/python test_hdf5_chunk_cache.py
.venv/bin/python hdf5-chunk-cache.py --repetitions 3 > observations.json

Measured environment: Python 3.12.3, h5py 3.15.0, HDF5 1.14.6, NumPy 2.3.3, zlib 1.3, Linux x86_64. File-format bounds are explicitly v110/v110. The harness uses no source data files or production datasets. Different library builds may produce different stored sizes or access behavior; investigate a failed control instead of overwriting the published expectations.

Primary sources

  1. The HDF Group (2015): Improving I/O Performance When Working with HDF5 Compressed Datasets, pp. 7-20
  2. The HDF Group: Chunking in HDF5, chunk caching and filters
  3. h5py 3.15: File objects, Python file-like objects and chunk cache
  4. h5py 3.15: Datasets, chunked storage and filter pipeline
  5. h5py low-level API: DatasetID.get_chunk_info_by_coord
  6. HDF5 1.14.6: H5Dchunk.c, edge filtering and chunk-cache paths
  7. HDF Group: error-detection policy and filter-failure callbacks
  8. HDF5 1.14.6: H5Z_pipeline and callback continuation
  9. HDF Group: H5Pset_filter, variable-length heaps and filter scope
  10. HDF Group: viewing tools, fixed-length and variable-length strings
  11. HDF Group: H5Dget_storage_size, raw dataset allocation
  12. h5py 3.15: string byte widths and silent truncation
  13. Koziol and Mainzer (2019): Variable Length Data in HDF5 Sketch Design

Cache sources checked 17 October; reader policy 19 October; string storage 20 October 2026. This is a bounded engineering observation, not a novel cache algorithm.

Published by Hesela team · Published · Updated

Report a correction · Editorial standards · Reuse guidance

Change history

: first published.

: latest recorded update. A detailed change note is not available for this revision.

New-publication RSS · Correction RSS

Cite this page
Hesela team. HDF5 chunk cache: more memory does not fix every reread. Hesela. 2026-10-20. https://hesela.com/analyses/hdf5-chunk-cache-read-amplification/