PostRefine: rank the observation cap on I/sigma worked out once, not per comparison

nth_element compared through pointers into gigabytes of partials, a cache miss per comparison on one
thread (0.3 s on a 16M sweep). The ratio is now computed beside each pointer on all threads; the
comparisons and so the selection and its order are the same.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D1G8gJVAy6gp1K5Dz3NE5C
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-09-26 22:51:31 +02:00
1 parent 2c48ed3fcd
commit dd02e65693
1 file changed
+13 -4
+13 -4
View File
@@ -487,10 +487,19 @@ PostRefineResult PostRefineRotationGeometry(PostRefineObservations observations,
});
constexpr size_t MAX_OBS = 20000;
if (n_obs > MAX_OBS) {
std::nth_element(obs.get(), obs.get() + MAX_OBS, obs.get() + n_obs,
[](const Partial *a, const Partial *b) {
return a->I / std::max(1e-9, static_cast<double>(a->sigma))
> b->I / std::max(1e-9, static_cast<double>(b->sigma)); });
// By I/sigma, with the ratio worked out once per observation beside it rather than at
// every comparison through the pointer: the same comparisons, so the same selection in
// the same order.
struct Ranked { double i_over_sigma; const Partial *p; };
std::vector<Ranked> ranked(n_obs);
ParallelChunks(static_cast<int>(n_obs), nthreads, [&](int lo, int hi) {
for (int i = lo; i < hi; ++i)
ranked[i] = {obs[i]->I / std::max(1e-9, static_cast<double>(obs[i]->sigma)), obs[i]};
});
std::nth_element(ranked.begin(), ranked.begin() + MAX_OBS, ranked.end(),
[](const Ranked &a, const Ranked &b) { return a.i_over_sigma > b.i_over_sigma; });
for (size_t i = 0; i < MAX_OBS; ++i)
obs[i] = ranked[i].p;
n_obs = MAX_OBS;
}
result.obs_used = static_cast<int>(n_obs);