Use BTreeMap for state.validators pending updates (#9017)

Closes:

- https://github.com/sigp/lighthouse/issues/9003


  Milhouse `List`s use a map in front of the binary tree to cache updates. Ever since we adopted Milhouse, we've been using `VecMap`, which is essentially `Vec<Option<T>>`. Turns out, when you've got 2M indices and only 2 non-`None` entries (changes), this is inefficient.

Milhouse is generic in the choice of map (`U: UpdateMap`) and has always supported `BTreeMap`, so this PR switches us over to `BTreeMap`. In previous benchmarks (years ago) it had been slower than `VecMap`, but now it is vastly superior.


Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
Michael Sproul
2026-03-24 12:43:19 +11:00
committed by GitHub
parent e21053311d
commit c451ae763c
3 changed files with 8 additions and 6 deletions

View File

@@ -4,8 +4,8 @@ use milhouse::List;
use std::sync::Arc;
use types::{
BeaconStateError, Epoch, EthSpec, ParticipationFlags, ProgressiveBalancesCache, SyncCommittee,
Validator,
consts::altair::{TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, TIMELY_TARGET_FLAG_INDEX},
state::Validators,
};
/// Provides a summary of validator participation during the epoch.
@@ -26,7 +26,7 @@ pub enum EpochProcessingSummary<E: EthSpec> {
#[derive(PartialEq, Debug)]
pub struct ParticipationEpochSummary<E: EthSpec> {
/// Copy of the validator registry prior to mutation.
validators: List<Validator, E::ValidatorRegistryLimit>,
validators: Validators<E>,
/// Copy of the participation flags for the previous epoch.
previous_epoch_participation: List<ParticipationFlags, E::ValidatorRegistryLimit>,
/// Copy of the participation flags for the current epoch.
@@ -37,7 +37,7 @@ pub struct ParticipationEpochSummary<E: EthSpec> {
impl<E: EthSpec> ParticipationEpochSummary<E> {
pub fn new(
validators: List<Validator, E::ValidatorRegistryLimit>,
validators: Validators<E>,
previous_epoch_participation: List<ParticipationFlags, E::ValidatorRegistryLimit>,
current_epoch_participation: List<ParticipationFlags, E::ValidatorRegistryLimit>,
previous_epoch: Epoch,