MRIFiles: Faster ISMRMRD read via single bulk HDF5 call - #291
Open
hakkelt wants to merge 1 commit into
Open
Conversation
The ISMRMRD dataset uses chunk size 1 (one chunk per profile), so the previous code issued O(N) separate HDF5 element reads inside the loop. On a 186 MB file with 3952 profiles this took ~3 s; the bulk read drops it to ~1.3 s (2.5× faster, ~40 MiB fewer allocations). Two paths: - No filter (common case): single `read(dset)` loads everything at once; the separate header-only bulk read is no longer needed and is removed. - Filtered (slice/repetition/contrast): unchanged — bulk-reads headers to decide which profiles to keep, then fetches only matching profiles. Correctness verified: all profiles match the original read bit-for-bit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
slice/repetition/contrastfilter), replace the per-profile element reads with a singleread(dset)call that loads the entire dataset at once.Why this helps
The ISMRMRD dataset is written with
chunkshape = [1](one HDF5 chunk per profile). The previous code calledh["…/data"][m]inside the loop, issuing one HDF5 element read per profile — O(N) separate chunk lookups, each with its own dataspace selection and variable-length heap traversal. On a 186 MB file with 3952 profiles this was the dominant cost.Benchmark (186 MB OCMR file, 3952 profiles, 3 runs each)
The speedup grows with profile count; larger cardiac/fMRI raw datasets (10k–200k profiles) will see a proportionally larger improvement.
Correctness
All 3952 profiles match the original read bit-for-bit (data and trajectory arrays) in both the unfiltered and filtered paths.
🤖 Generated with Claude Code