From 0180711ae4824d57db183ffde648ee2bc8cb2957 Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Thu, 31 Jul 2025 01:56:39 -0400 Subject: [PATCH] perf: Constrain memory size again, add log --- src/pseudo_peer/sources/hl_node.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pseudo_peer/sources/hl_node.rs b/src/pseudo_peer/sources/hl_node.rs index 2d7321986..f2c402296 100644 --- a/src/pseudo_peer/sources/hl_node.rs +++ b/src/pseudo_peer/sources/hl_node.rs @@ -1,5 +1,4 @@ use std::{ - collections::HashMap, fs::File, io::{BufRead, BufReader, Read, Seek, SeekFrom}, ops::RangeInclusive, @@ -8,6 +7,7 @@ use std::{ }; use futures::future::BoxFuture; +use reth_network::cache::LruMap; use rangemap::RangeInclusiveMap; use serde::Deserialize; use time::{macros::format_description, Date, Duration, OffsetDateTime, Time}; @@ -23,14 +23,20 @@ const HOURLY_SUBDIR: &str = "hourly"; #[derive(Debug)] pub struct LocalBlocksCache { - cache: HashMap, + cache: LruMap, // Lightweight range map to track the ranges of blocks in the local ingest directory ranges: RangeInclusiveMap, } impl LocalBlocksCache { + // 3660 blocks per hour + const CACHE_SIZE: u32 = 8000; + fn new() -> Self { - Self { cache: HashMap::new(), ranges: RangeInclusiveMap::new() } + Self { + cache: LruMap::new(Self::CACHE_SIZE), + ranges: RangeInclusiveMap::new(), + } } fn load_scan_result(&mut self, scan_result: ScanResult) { @@ -215,6 +221,7 @@ impl HlNodeBlockSource { return None; }; + info!("Loading block data from {:?}", path); u_cache.load_scan_result(scan_hour_file(&path, &mut 0, height)); u_cache.cache.get(&height).cloned() }