From f3a405655cfbf74bd30374eca898d8d71d439e26 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 11 Oct 2026 23:09:15 +0200 Subject: [PATCH] rugnux: a near-tie re-check of a first pass already re-checked on the same inputs is not run again A run can make the same first pass several times - the canonical pass and the probes at the geometry it stands at - and each of them that carried a near tie left its own re-check. The first pass is deterministic in its inputs (FirstPassInputKey, the key the first-pass memo already trusts), deciding late as deciding early, so a re-check whose pass read the same inputs (and the same pre-pass flag) as an earlier one takes that one's outcome instead of running again. Measured on 4p8r (8 re-checks, 5 on inputs of their own): re-checks 18.7 -> 13.5 s, p.hkl identical. A diagnostic build that runs the skipped re-checks anyway and compares is used to check the outcomes agree. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EizBKhTqrAYago9KJG3dA3 --- rugnux/Rugnux.cpp | 31 +++++++++++++++++++++++-------- rugnux/Rugnux.h | 3 +++ rugnux/RugnuxFirstPass.cpp | 1 + 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/rugnux/Rugnux.cpp b/rugnux/Rugnux.cpp index f39cb79e5..1935e9a3a 100644 --- a/rugnux/Rugnux.cpp +++ b/rugnux/Rugnux.cpp @@ -442,7 +442,8 @@ void Rugnux::StartNearTieRecheck(std::shared_ptr run, bool geometry_prep run->rotation_scale_check_.reset(); run->gpu_work_beside_ = false; // it runs after the run, on its own std::lock_guard lock(near_tie_rechecks_->m); - near_tie_rechecks_->pending.push_back({std::move(run), geometry_prepass, first_pass_outcome_}); + near_tie_rechecks_->pending.push_back({std::move(run), geometry_prepass, first_pass_outcome_, + first_pass_input_key_}); } bool Rugnux::NearTieOverturned() { @@ -451,11 +452,25 @@ bool Rugnux::NearTieOverturned() { TimingMark mark(logger, "near-tie re-checks"); std::lock_guard lock(near_tie_rechecks_->m); int elsewhere = 0; - for (auto &[run, geometry_prepass, outcome] : near_tie_rechecks_->pending) { - try { - run->RunPipeline(nullptr, /*write_output=*/false, geometry_prepass); - } catch (const NoLatticeFound &) { - run->first_pass_outcome_.clear(); // the pass found one; on all the frames it finds none + int run_again = 0; + auto &pending = near_tie_rechecks_->pending; + for (size_t i = 0; i < pending.size(); i++) { + auto &[run, geometry_prepass, outcome, key] = pending[i]; + // A first pass the run made more than once on the same inputs - a probe at the geometry the + // pass stands at - is re-checked once: the first pass is deterministic in its inputs + // (FirstPassInputKey), deciding late as deciding early. + const auto same = std::find_if(pending.begin(), pending.begin() + i, [&](const auto &q) { + return q.key == key && q.geometry_prepass == geometry_prepass; + }); + if (same != pending.begin() + i) { + run->first_pass_outcome_ = same->run->first_pass_outcome_; + } else { + run_again++; + try { + run->RunPipeline(nullptr, /*write_output=*/false, geometry_prepass); + } catch (const NoLatticeFound &) { + run->first_pass_outcome_.clear(); // the pass found one; on all the frames it finds none + } } if (run->first_pass_outcome_ != outcome) { logger.Info("Near-tie re-check: the first pass ends elsewhere on all the frames - {} against {}", @@ -464,8 +479,8 @@ bool Rugnux::NearTieOverturned() { } } if (!near_tie_rechecks_->pending.empty()) - logger.Info("Near ties re-checked on the rest of the sweep: {} first pass(es), {} ending elsewhere", - near_tie_rechecks_->pending.size(), elsewhere); + logger.Info("Near ties re-checked on the rest of the sweep: {} first pass(es), {} of them on inputs " + "of their own, {} ending elsewhere", pending.size(), run_again, elsewhere); near_tie_rechecks_->pending.clear(); if (near_tie_rechecks_->radius_elsewhere) elsewhere++; diff --git a/rugnux/Rugnux.h b/rugnux/Rugnux.h index 43f16bc72..0e3af02f4 100644 --- a/rugnux/Rugnux.h +++ b/rugnux/Rugnux.h @@ -998,6 +998,8 @@ class Rugnux { // What the last first pass ended on - the lattice, the path to it, the centre and the spot-finding // settings it stands on, the centres it carries forward - for its re-check to compare with. std::string first_pass_outcome_; + // The inputs that first pass read (FirstPassInputKey), for re-checks of the same pass to be run once. + std::vector first_pass_input_key_; // The re-checks of the whole run, shared with the copies the run makes of itself: a probe on a copy // leaves its re-check here too. struct NearTieRechecks { @@ -1005,6 +1007,7 @@ class Rugnux { std::shared_ptr run; // the run as the pass found it bool geometry_prepass; std::string outcome; // what its first pass ended on + std::vector key; // the inputs that first pass read }; // A metric-symmetry check decided on the pre-pass frames within its noise (see RefinedPasses): // the demoted arm, to run again on every frame and be judged against the promoted arm's fit diff --git a/rugnux/RugnuxFirstPass.cpp b/rugnux/RugnuxFirstPass.cpp index 9afa3cacd..634d081ed 100644 --- a/rugnux/RugnuxFirstPass.cpp +++ b/rugnux/RugnuxFirstPass.cpp @@ -359,6 +359,7 @@ bool Rugnux::FirstPassRotationIndexing(PipelineLocals &p) { // An indexing probe over inputs a first pass has already been run on returned above, except // under verify_first_pass_memo, which runs the pass and compares. const std::vector first_pass_key = FirstPassInputKey(); + first_pass_input_key_ = first_pass_key; std::optional memo_hit; const auto memo = std::find_if(first_pass_memo_.begin(), first_pass_memo_.end(), [&](const FirstPassMemo &m) { return m.key == first_pass_key; });