Skip to content

Conversation

@HaoranYi
Copy link

@HaoranYi HaoranYi commented Oct 15, 2025

Problem

The leader_slots_map in LeaderSchedule uses HashMap<Pubkey, Arc<Vec<usize>>>, but the Arc wrapping is unnecessary overhead.

The Arc was previously needed because get_leader_upcoming_slots returned a boxed iterator requiring ownership of the Vec. This forced cloning of the Arc on every call.

Summary of Changes

Changed HashMap<Pubkey, Arc<Vec<usize>>> to HashMap<Pubkey, Vec<usize>> in the leader schedule implementation.

By modifying get_leader_upcoming_slots to return a borrowed iterator (Box<dyn Iterator + '_>), and collecting the Arc<LeaderSchedule> references upfront in next_leader_slot, the schedules stay alive for the entire iterator chain, eliminating the need for Arc wrapping and avoiding intermediate Vec allocations.

Changes:

  • Updated trait method signature and implementations
  • Simplified invert_slot_leaders to return HashMap without Arc wrapping
  • Modified get_leader_upcoming_slots to return borrowed iterator
  • Collect leader schedules in next_leader_slot before creating iterators
  • Removed Arc imports from identity_keyed and vote_keyed modules

Fixes #

@HaoranYi HaoranYi force-pushed the remove-arc-from-leader-slots-map branch from 4e4163a to 2b1a259 Compare October 15, 2025 15:58
Changed `HashMap<Pubkey, Arc<Vec<usize>>>` to `HashMap<Pubkey, Vec<usize>>`
in the leader schedule implementation.

The Arc was previously needed because `get_leader_upcoming_slots` returned
a boxed iterator requiring ownership of the Vec. By modifying the method to
return a borrowed iterator (`Box<dyn Iterator + '_>`), and collecting the
Arc<LeaderSchedule> references upfront in `next_leader_slot`, the schedules
stay alive for the entire iterator chain, eliminating the need for Arc
wrapping and avoiding intermediate Vec allocations.

Changes:
- Updated trait method signature and implementations
- Simplified `invert_slot_leaders` to return HashMap without Arc wrapping
- Modified `get_leader_upcoming_slots` to return borrowed iterator
- Collect leader schedules in `next_leader_slot` before creating iterators
- Removed Arc imports from identity_keyed and vote_keyed modules
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.1%. Comparing base (a849f2f) to head (63cee94).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #8499    +/-   ##
========================================
  Coverage    83.1%    83.1%            
========================================
  Files         848      848            
  Lines      368309   368314     +5     
========================================
+ Hits       306273   306431   +158     
+ Misses      62036    61883   -153     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

.map(|epoch| self.get_epoch_schedule_else_compute(epoch, bank))
.while_some()
.zip(epoch..)
.collect();
Copy link
Member

@vadorovsky vadorovsky Oct 15, 2025

Choose a reason for hiding this comment

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

Did you have a chance to measure how much does this collect take? This change looks like a trade-off - slower next_leader_slot (the question is - how much) for faster epoch boundary (~5ms).

I can profile it, but I'm AFK now, so I could do it tomorrow.

Copy link
Author

Choose a reason for hiding this comment

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

It will be small. There is going to be at most two Arc of leader schedules.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, it's like 0.1ms per each replay.

next_leader_slot

Copy link
Member

@vadorovsky vadorovsky left a comment

Choose a reason for hiding this comment

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

Awesome work, thanks! :shipit:

@vadorovsky
Copy link
Member

pls merge whenever you can, so I can put better profiles in #8451 🙂

@HaoranYi HaoranYi added this pull request to the merge queue Oct 17, 2025
@HaoranYi
Copy link
Author

HaoranYi commented Oct 17, 2025

pls merge whenever you can, so I can put better profiles in #8451 🙂

Yeah, it’s merged. Brooks is on vacation, so let’s skip his approval for now — if he has any feedback later, we can handle it in a follow-up PR.

Merged via the queue into anza-xyz:master with commit a486046 Oct 17, 2025
43 checks passed
@HaoranYi HaoranYi deleted the remove-arc-from-leader-slots-map branch October 17, 2025 14:01
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.

4 participants