Problem
lachesis_labels already computes a candidate diameter and incrementally updates it while extending a stop. When return_anchors=True and the stop is accepted, it starts again at the first point and repeats _update_diameter through the full stop solely to recover the diameter witnesses used for anchor_time.
For a stop with m pings, the normal scan performs quadratic pair-distance work. The second witness pass performs another quadratic pass. _update_diameter already supports carrying witness_index, so the extension from j_star through j_final should not be repeated.
The initial i through j_star window needs separate handling because _diameter(..., witness=True) returns the witness for the complete window, not the witness for every prefix.
Proposed change
When return_anchors=True:
- Build the initial candidate incrementally from
i, recording the witness for each prefix through j_star.
- Carry the same diameter and witness state through the existing extension loop.
- Retain the recorded anchor values only if the candidate is accepted as a stop.
- Remove the post-acceptance loop that recomputes the diameter through the full stop.
Keep the current path unchanged when return_anchors=False.
Acceptance criteria
- Stop labels do not change.
anchor_time preserves the current earliest-witness behavior, including ties.
- Euclidean and haversine metrics are covered.
- An accepted stop does not trigger a second
_update_diameter pass over the same pings.
- A focused call-count test or benchmark demonstrates that the redundant distance work was removed.
This pull request includes code written with the assistance of AI. The code has not yet been reviewed by a human (remove this disclosure after human review).
Problem
lachesis_labelsalready computes a candidate diameter and incrementally updates it while extending a stop. Whenreturn_anchors=Trueand the stop is accepted, it starts again at the first point and repeats_update_diameterthrough the full stop solely to recover the diameter witnesses used foranchor_time.For a stop with m pings, the normal scan performs quadratic pair-distance work. The second witness pass performs another quadratic pass.
_update_diameteralready supports carryingwitness_index, so the extension fromj_starthroughj_finalshould not be repeated.The initial
ithroughj_starwindow needs separate handling because_diameter(..., witness=True)returns the witness for the complete window, not the witness for every prefix.Proposed change
When
return_anchors=True:i, recording the witness for each prefix throughj_star.Keep the current path unchanged when
return_anchors=False.Acceptance criteria
anchor_timepreserves the current earliest-witness behavior, including ties._update_diameterpass over the same pings.This pull request includes code written with the assistance of AI. The code has not yet been reviewed by a human (remove this disclosure after human review).