Skip to content

Avoid recomputing Lachesis diameters when return_anchors=True #431

Description

@paco-barreras

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions