Use rebasing to minimise BeaconState mem usage (#4416)

* Use "rebasing" to minimise BeaconState mem usage

* Update metastruct

* Use upstream milhouse, update cargo lock

* Rebase caches for extra memory savings
This commit is contained in:
Michael Sproul
2023-06-21 11:05:09 +10:00
committed by GitHub
parent 6eb151396d
commit ca412ab3f0
4 changed files with 152 additions and 7 deletions

View File

@@ -1253,12 +1253,35 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
);
assert_eq!(summary.diff_base_slot, state.slot());
let mut base_buffer = HDiffBuffer::from_state(state);
let t = std::time::Instant::now();
let pre_state = state.clone();
let mut base_buffer = HDiffBuffer::from_state(pre_state.clone());
diff.apply(&mut base_buffer)?;
state = base_buffer.into_state(&self.spec)?;
let application_ms = t.elapsed().as_millis();
// Rebase state before adding it to the cache, to ensure it uses minimal memory.
let t = std::time::Instant::now();
state.rebase_on(&pre_state, &self.spec)?;
let rebase_ms = t.elapsed().as_millis();
let t = std::time::Instant::now();
state.update_tree_hash_cache()?;
let tree_hash_ms = t.elapsed().as_millis();
let t = std::time::Instant::now();
state.build_all_caches(&self.spec)?;
let cache_ms = t.elapsed().as_millis();
debug!(
self.log,
"State diff applied";
"application_ms" => application_ms,
"rebase_ms" => rebase_ms,
"tree_hash_ms" => tree_hash_ms,
"cache_ms" => cache_ms,
"slot" => state.slot()
);
// Add state to the cache, it is by definition an epoch boundary state and likely
// to be useful.