Skip to content

fix: replace O(n²) path dedup with O(1) hash set lookup#7070

Draft
dangell7 wants to merge 1 commit intodevelopfrom
dangell7/fix-pathfinder-dedup
Draft

fix: replace O(n²) path dedup with O(1) hash set lookup#7070
dangell7 wants to merge 1 commit intodevelopfrom
dangell7/fix-pathfinder-dedup

Conversation

@dangell7
Copy link
Copy Markdown
Collaborator

@dangell7 dangell7 commented May 4, 2026

High Level Overview of Change

Context of Change

addUniquePath was using linear scan to check for duplicate paths,
resulting in ~500k comparisons at PATHFINDER_MAX_COMPLETE_PATHS=1000.

  • Expose STPathElement::hash() accessor (existing precomputed field)
  • Add STPathHash functor combining element hashes via boost hash_combine pattern
  • Maintain a parallel unordered_set index alongside completePaths_ for O(1) dedup

The original code had a TODO acknowledging the issue:

// TODO(tom): building an STPathSet this way is quadratic in the size
// of the STPathSet!

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

@dangell7 dangell7 force-pushed the dangell7/fix-pathfinder-dedup branch from 2320d69 to 873778b Compare May 4, 2026 16:27
@dangell7 dangell7 force-pushed the dangell7/fix-pathfinder-dedup branch from 873778b to f4e1dc7 Compare May 4, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant