Skip to content

perf(serde_snapshot): build versioned epoch stakes in thread#10002

Merged
kskalski merged 2 commits intoanza-xyz:masterfrom
kskalski:ks/perf_epoch_stakes
Jan 15, 2026
Merged

perf(serde_snapshot): build versioned epoch stakes in thread#10002
kskalski merged 2 commits intoanza-xyz:masterfrom
kskalski:ks/perf_epoch_stakes

Conversation

@kskalski
Copy link
Copy Markdown

@kskalski kskalski commented Jan 14, 2026

Problem

#9831 changed deserialization of epoch stakes to intermediate representation as cheaper vectors, but at some point the final im::HashMap need to be constructed, which is a slow CPU-bound process (can take even >8s). Current this is done serially after accounts db index is built.

Since this part of bank data initialization is independent from calculating accounts db, it could be done in separate thread such that it's ready once accounts db reconstruction is done.

Summary of Changes

  • change versioned_epoch_stakes in BankFieldsToDeserialize to Vec (this makes deserialization even slightly cheaper), since it's intermediate representation that is only iterated on later
  • create final HashMap<Epoch, VersionedEpochStakes> in separate thread spawned before reconstruct_accountsdb_from_fields
  • pass the map to Bank::new_from_snapshot to be used instead of reading from fields.versioned_epoch_stakes
Performance change

Time between loading stakes and finishing new_from_snapshot (rent_collector log line) shrinks from 4.22s to 0.011s

PR

[2026-01-14T06:53:03.140175595Z INFO  solana_runtime::bank] Loading Stakes took:  took 2.4s
[2026-01-14T06:53:03.151382107Z INFO  solana_runtime::serde_snapshot] rent_collector: RentCollector { epoch: 910, epoch_schedule: EpochSchedule { slots_per_epoch: 432000, leader_schedule_slot_offset: 432000, warmup: false, first_normal_epoch: 0, first_normal_slot: 0 }, slots_per_year: 78892314.984, rent: Rent { lamports_per_byte_year: 3480, exemption_threshold: 2.0, burn_percent: 50 } }
[2026-01-14T06:53:03.151403837Z INFO  solana_runtime::snapshot_bank_utils] rebuild bank from snapshots took 61.1s

master

[2026-01-14T07:11:55.046225292Z INFO  solana_runtime::bank] Loading Stakes took:  took 2.5s
[2026-01-14T07:11:59.261691409Z INFO  solana_runtime::serde_snapshot] rent_collector: RentCollector { epoch: 910, epoch_schedule: EpochSchedule { slots_per_epoch: 432000, leader_schedule_slot_offset: 432000, warmup: false, first_normal_epoch: 0, first_normal_slot: 0 }, slots_per_year: 78892314.984, rent: Rent { lamports_per_byte_year: 3480, exemption_threshold: 2.0, burn_percent: 50 } }
[2026-01-14T07:11:59.261725947Z INFO  solana_runtime::snapshot_bank_utils] rebuild bank from snapshots took 66.3s

@kskalski kskalski force-pushed the ks/perf_epoch_stakes branch from af1c0e9 to a3842ca Compare January 14, 2026 10:46
@kskalski kskalski marked this pull request as ready for review January 14, 2026 11:41
@kskalski kskalski requested a review from brooksprumo January 14, 2026 11:41
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.5%. Comparing base (729712b) to head (5e174c5).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10002   +/-   ##
=======================================
  Coverage    82.5%    82.5%           
=======================================
  Files         844      844           
  Lines      316758   316780   +22     
=======================================
+ Hits       261579   261622   +43     
+ Misses      55179    55158   -21     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment thread runtime/src/bank.rs
Comment thread runtime/src/bank.rs
@kskalski kskalski requested a review from brooksprumo January 15, 2026 00:46
Copy link
Copy Markdown

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

:shipit:

@kskalski kskalski added this pull request to the merge queue Jan 15, 2026
Merged via the queue into anza-xyz:master with commit b4f607f Jan 15, 2026
47 checks passed
@kskalski kskalski deleted the ks/perf_epoch_stakes branch January 15, 2026 14:11
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.

3 participants