Skip to content

Cache detector module slices in FormatNXmx to avoid redundant HDF5 reads#881

Open
dwmoreau wants to merge 3 commits into
mainfrom
nexus_module_slice_cache
Open

Cache detector module slices in FormatNXmx to avoid redundant HDF5 reads#881
dwmoreau wants to merge 3 commits into
mainfrom
nexus_module_slice_cache

Conversation

@dwmoreau

Copy link
Copy Markdown
Contributor

get_raw_data() was re-parsing the nxmx object tree and recomputing detector module slices on every call, triggering hundreds of thousands of HDF5 attribute reads for data_origin and data_size per dataset. Cache nxdata, nxdetector, and the module slices in _start(), where other static detector properties are already cached, and thread the precomputed slices through to the get_raw_data functions in nexus/init.py and FormatNXmxEigerFilewriter.

Developed with assistance from Claude Code (claude-opus-4-6)

get_raw_data() was re-parsing the nxmx object tree and recomputing
detector module slices on every call, triggering hundreds of thousands
of HDF5 attribute reads for data_origin and data_size per dataset.
Cache nxdata, nxdetector, and the module slices in _start(), where
other static detector properties are already cached, and thread the
precomputed slices through to the get_raw_data functions in
nexus/__init__.py and FormatNXmxEigerFilewriter.

Developed with assistance from Claude Code (claude-opus-4-6)
@dwmoreau dwmoreau requested a review from phyy-nx April 15, 2026 19:02
@ndevenish ndevenish self-requested a review April 15, 2026 20:58
@phyy-nx

phyy-nx commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Here's a little snippet you can run without running any processing to show the time savings of this PR:

time libtbx.python -c "import dxtbx; from dials.array_family import flex; img = dxtbx.load('`dials.data get -q lysozyme_JF16M_4img`/lyso009a_0087.JF07T32V01_master_4img.h5'); print([sum([flex.sum(p) for p in img.get_raw_data(i%img.get_num_images())]) for i in range(100)])"

It's messy, but what it does is read a 4-img JF16M dataset (256 panels) and call get_raw_data 100 times, 25 times per image. It prints out the sum of the panels each time to verify it's the same on main and on the feature branch (which it is). On my computer it runs in ~24s on main and ~20s on the feature branch.

@phyy-nx phyy-nx moved this from Need larger review to In progress in DIALS Spring Performance Updates Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants