The per-image geometry refinement is the largest stage of the image loop, and a
third of it was arithmetic on numbers that never change.
The residual derives the detector angles' sines and cosines, the goniometer's
back-rotation - a three-argument hypot, a sine, a cosine and a division - and the
reciprocal basis of the cell on every evaluation. On the rotation path the detector
angles and the axis are held fixed and stored as plain doubles, so all of it is
constant, not merely constant per block: there is one frame per image and one cell.
Three solves an image, fifty iterations a solve and a thousand spots make it tens of
thousands of repetitions of the same result. The frame's constants are now built
once and handed in. The body they feed is the same body, split out rather than
copied, so no expression is reassociated - in particular the reciprocal vector is
still formed as the basis times the inverse volume, with the volume not folded into
the basis.
The spot confidence weights depend only on each spot's resolution and intensity,
which no solver touches, and were recomputed identically for each of the three
passes. They are computed once. The sort behind them ordered indices through a
projection that chased a random eighty-byte-strided element per comparison; it now
sorts a packed resolution and index, which makes the same comparisons in the same
sequence and therefore the same permutation. The spot list itself was copied per
image through an initializer list whose elements are const; it is passed as a view.
The integration engine was the last one in the loop copying through pageable host
memory - three transfers in and eight out per image, twenty-six bytes a reflection,
while every other engine already page-locks its staging. A driver copy from pageable
memory stages through its own pinned buffer on the calling thread, which is why an
asynchronous copy was averaging a hundred and thirteen microseconds. Page-locked, the
same seventeen thousand calls cost four hundred and thirty-two milliseconds instead
of one and a half seconds, and the wait moves to the synchronisation point where it
belongs.
Two smaller ones: the reflections were copied into the per-image message for a
process file that a merging run does not write, so the copy is made where a writer
exists; and the intensity statistics and the Wilson estimate walked the same
eighty-byte array twice to read twelve bytes, which is now one pass with each
accumulation in its own order.
Every reflection file is byte-identical on four crystals; the process file's
reflections match dataset for dataset, and its azimuthal arrays differ no more
between this build and the last than the last differs from itself.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EGpGdgmJ8MyY9pCGWjktyi