deps: replace lru with schnellru (#1217)

* deps: replace lru with schnellru

* bring the peace to the galaxy
This commit is contained in:
ordian
2023-08-28 19:04:11 +02:00
committed by GitHub
parent 7125f65fe6
commit c168a77e26
32 changed files with 207 additions and 241 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ polkadot-node-metrics = { path = "../metrics" }
polkadot-primitives = { path = "../../primitives" }
orchestra = "0.0.5"
gum = { package = "tracing-gum", path = "../gum" }
lru = "0.11.0"
schnellru = "0.2.1"
sp-core = { path = "../../../substrate/primitives/core" }
async-trait = "0.1.57"
tikv-jemalloc-ctl = { version = "0.5.0", optional = true }
+2 -2
View File
@@ -19,9 +19,9 @@ use crate::{
Overseer, OverseerMetrics, OverseerSignal, OverseerSubsystemContext, SpawnGlue,
KNOWN_LEAVES_CACHE_SIZE,
};
use lru::LruCache;
use orchestra::{FromOrchestra, SpawnedSubsystem, Subsystem, SubsystemContext};
use polkadot_node_subsystem_types::{errors::SubsystemError, messages::*};
use schnellru::{ByLength, LruMap};
// Generated dummy messages
use crate::messages::*;
@@ -193,7 +193,7 @@ where
.activation_external_listeners(Default::default())
.span_per_active_leaf(Default::default())
.active_leaves(Default::default())
.known_leaves(LruCache::new(KNOWN_LEAVES_CACHE_SIZE))
.known_leaves(LruMap::new(ByLength::new(KNOWN_LEAVES_CACHE_SIZE)))
.spawner(SpawnGlue(spawner))
.metrics(metrics)
.supports_parachains(supports_parachains);
+5 -8
View File
@@ -62,14 +62,13 @@
use std::{
collections::{hash_map, HashMap},
fmt::{self, Debug},
num::NonZeroUsize,
pin::Pin,
sync::Arc,
time::Duration,
};
use futures::{channel::oneshot, future::BoxFuture, select, Future, FutureExt, StreamExt};
use lru::LruCache;
use schnellru::LruMap;
use client::{BlockImportNotification, BlockchainEvents, FinalityNotification};
use polkadot_primitives::{Block, BlockNumber, Hash};
@@ -113,10 +112,7 @@ pub use orchestra::{
/// Store 2 days worth of blocks, not accounting for forks,
/// in the LRU cache. Assumes a 6-second block time.
pub const KNOWN_LEAVES_CACHE_SIZE: NonZeroUsize = match NonZeroUsize::new(2 * 24 * 3600 / 6) {
Some(cap) => cap,
None => panic!("Known leaves cache size must be non-zero"),
};
pub const KNOWN_LEAVES_CACHE_SIZE: u32 = 2 * 24 * 3600 / 6;
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
mod memory_stats;
@@ -632,7 +628,7 @@ pub struct Overseer<SupportsParachains> {
pub supports_parachains: SupportsParachains,
/// An LRU cache for keeping track of relay-chain heads that have already been seen.
pub known_leaves: LruCache<Hash, ()>,
pub known_leaves: LruMap<Hash, ()>,
/// Various Prometheus metrics.
pub metrics: OverseerMetrics,
@@ -880,9 +876,10 @@ where
let span = Arc::new(span);
self.span_per_active_leaf.insert(*hash, span.clone());
let status = if let Some(_) = self.known_leaves.put(*hash, ()) {
let status = if self.known_leaves.get(hash).is_some() {
LeafStatus::Stale
} else {
self.known_leaves.insert(*hash, ());
LeafStatus::Fresh
};