mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
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:
@@ -14,6 +14,7 @@ use serde::{Deserialize, Deserializer, Serialize};
|
||||
use ssz::{Decode, DecodeError, Encode, ssz_encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::{BitVector, FixedVector};
|
||||
use std::collections::BTreeMap;
|
||||
use superstruct::superstruct;
|
||||
use swap_or_not_shuffle::compute_shuffled_index;
|
||||
use test_random_derive::TestRandom;
|
||||
@@ -58,7 +59,8 @@ pub const CACHED_EPOCHS: usize = 3;
|
||||
const MAX_RANDOM_BYTE: u64 = (1 << 8) - 1;
|
||||
const MAX_RANDOM_VALUE: u64 = (1 << 16) - 1;
|
||||
|
||||
pub type Validators<E> = List<Validator, <E as EthSpec>::ValidatorRegistryLimit>;
|
||||
pub type Validators<E> =
|
||||
List<Validator, <E as EthSpec>::ValidatorRegistryLimit, BTreeMap<usize, Validator>>;
|
||||
pub type Balances<E> = List<u64, <E as EthSpec>::ValidatorRegistryLimit>;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
@@ -453,7 +455,7 @@ where
|
||||
// Registry
|
||||
#[compare_fields(as_iter)]
|
||||
#[test_random(default)]
|
||||
pub validators: List<Validator, E::ValidatorRegistryLimit>,
|
||||
pub validators: Validators<E>,
|
||||
#[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")]
|
||||
#[compare_fields(as_iter)]
|
||||
#[test_random(default)]
|
||||
|
||||
@@ -17,7 +17,7 @@ pub use balance::Balance;
|
||||
pub use beacon_state::{
|
||||
BeaconState, BeaconStateAltair, BeaconStateBase, BeaconStateBellatrix, BeaconStateCapella,
|
||||
BeaconStateDeneb, BeaconStateElectra, BeaconStateError, BeaconStateFulu, BeaconStateGloas,
|
||||
BeaconStateHash, BeaconStateRef, CACHED_EPOCHS,
|
||||
BeaconStateHash, BeaconStateRef, CACHED_EPOCHS, Validators,
|
||||
};
|
||||
pub use committee_cache::{
|
||||
CommitteeCache, compute_committee_index_in_epoch, compute_committee_range_in_epoch,
|
||||
|
||||
Reference in New Issue
Block a user