Skip to content

Sort entry pointers in convertToBucketEntry.#5291

Open
dmkozh wants to merge 1 commit into
stellar:masterfrom
dmkozh:entry_sort
Open

Sort entry pointers in convertToBucketEntry.#5291
dmkozh wants to merge 1 commit into
stellar:masterfrom
dmkozh:entry_sort

Conversation

@dmkozh
Copy link
Copy Markdown
Contributor

@dmkozh dmkozh commented May 23, 2026

Description

Sort entry pointers in convertToBucketEntry.

This avoids O(n log n) swaps of potentially large structs.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

This avoids O(n log n) swaps of potentially large structs.
Copilot AI review requested due to automatic review settings May 23, 2026 00:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates LiveBucket::convertToBucketEntry to sort pointers to BucketEntry objects (rather than sorting the BucketEntry objects themselves), aiming to reduce the cost of std::sort swapping large structs during bucket creation in Stellar Core’s bucket subsystem.

Changes:

  • Build an unsorted entries vector of BucketEntry objects and a parallel vector of pointers to those objects.
  • Sort the pointer vector using the existing BucketEntryIdCmp<LiveBucket> comparator.
  • Materialize the final sorted bucket vector by moving elements in sorted pointer order.

Comment thread src/bucket/LiveBucket.cpp
Comment on lines +389 to +393
std::vector<BucketEntry> entries;
entries.reserve(totalSize);

std::vector<BucketEntry*> sortedEntries;
sortedEntries.reserve(totalSize);
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.

2 participants