From 10435ef5880bc2ffed4eeabd43c1f23b3fd224b2 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 9 Sep 2026 16:40:57 +0200 Subject: [PATCH] miniCBF: read the sweep's rotation angles on several threads Opening a sweep parses the header of every file to get its start angle, and one header is two dozen std::regex searches: measured at 0.33 ms on a 16 Mpx sweep and 1.0 ms on one with a longer header, so a 7200-frame sweep spent 7.2 s on one thread before it read an image. The files are independent, so the scan is shared out over up to eight of them. Co-Authored-By: Claude Opus 5 (1M context) --- reader/JFJochCBFReader.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/reader/JFJochCBFReader.cpp b/reader/JFJochCBFReader.cpp index 3b1edc7a4..7d554119f 100644 --- a/reader/JFJochCBFReader.cpp +++ b/reader/JFJochCBFReader.cpp @@ -8,8 +8,10 @@ #include #include #include +#include #include #include +#include #include "../common/JFJochException.h" #include "../common/Logger.h" @@ -258,10 +260,21 @@ void JFJochCBFReader::ReadFiles(const std::string &path) { std::chrono::duration_cast( std::chrono::duration(header0_.exposure_s))); - // The rotation angle of every image, from its own header. + // The rotation angle of every image, from its own header. Parsing one costs a few hundred + // microseconds - it is two dozen regular expressions - so on a sweep of several thousand frames + // this is seconds of startup before a single image is read, and the files are independent. std::vector angles(files_.size()); - for (size_t i = 0; i < files_.size(); i++) - angles[i] = minicbf::ReadHeader(files_[i]).start_angle_deg; + { + const size_t nthreads = std::min(std::max(1u, std::thread::hardware_concurrency()), 8); + std::vector> futures; + for (size_t t = 0; t < nthreads; t++) + futures.push_back(std::async(std::launch::async, [&, t] { + for (size_t i = t; i < files_.size(); i += nthreads) + angles[i] = minicbf::ReadHeader(files_[i]).start_angle_deg; + })); + for (auto &f : futures) + f.get(); + } double increment = header0_.angle_increment_deg; if (files_.size() > 1) {