global: speed improvement

This commit is contained in:
nym21
2026-04-09 11:52:01 +02:00
parent c5c49f62d1
commit 21a0226a19
20 changed files with 1489 additions and 4942 deletions
@@ -1,6 +1,6 @@
use std::time::{SystemTime, UNIX_EPOCH};
use brk_error::Result;
use brk_error::{OptionData, Result};
use brk_types::{DifficultyAdjustment, Epoch, Height};
use vecdb::ReadableVec;
@@ -25,7 +25,7 @@ impl Query {
.height
.epoch
.collect_one(current_height)
.unwrap();
.data()?;
let current_epoch_usize: usize = current_epoch.into();
// Get epoch start height
@@ -34,7 +34,7 @@ impl Query {
.epoch
.first_height
.collect_one(current_epoch)
.unwrap();
.data()?;
let epoch_start_u32: u32 = epoch_start_height.into();
// Calculate epoch progress
@@ -49,13 +49,13 @@ impl Query {
.timestamp
.epoch
.collect_one(current_epoch)
.unwrap();
.data()?;
let current_timestamp = indexer
.vecs
.blocks
.timestamp
.collect_one(current_height)
.unwrap();
.data()?;
// Calculate average block time in current epoch
let elapsed_time = (*current_timestamp - *epoch_start_timestamp) as u64;
@@ -92,20 +92,20 @@ impl Query {
.epoch
.first_height
.collect_one(prev_epoch)
.unwrap();
.data()?;
let prev_difficulty = indexer
.vecs
.blocks
.difficulty
.collect_one(prev_epoch_start)
.unwrap();
.data()?;
let curr_difficulty = indexer
.vecs
.blocks
.difficulty
.collect_one(epoch_start_height)
.unwrap();
.data()?;
let retarget = if *prev_difficulty > 0.0 {
((*curr_difficulty / *prev_difficulty) - 1.0) * 100.0
+4 -4
View File
@@ -1,4 +1,4 @@
use brk_error::Result;
use brk_error::{OptionData, Result};
use brk_types::{DifficultyEntry, HashrateEntry, HashrateSummary, Height, TimePeriod};
use vecdb::{ReadableOptionVec, ReadableVec, VecIndex};
@@ -17,7 +17,7 @@ impl Query {
.blocks
.difficulty
.collect_one(current_height)
.unwrap();
.data()?;
// Get current hashrate
let current_day1 = computer
@@ -25,7 +25,7 @@ impl Query {
.height
.day1
.collect_one(current_height)
.unwrap();
.data()?;
let current_hashrate = *computer
.mining
@@ -49,7 +49,7 @@ impl Query {
.height
.day1
.collect_one(Height::from(start))
.unwrap();
.data()?;
let end_day1 = current_day1;
// Sample at regular intervals to avoid too many data points
+17 -12
View File
@@ -291,20 +291,25 @@ impl Query {
let computer = self.computer();
let max_height = self.height().to_usize();
let start = start_height.map(|h| h.to_usize()).unwrap_or(max_height);
let reader = computer.pools.pool.reader();
let end = start.min(reader.len().saturating_sub(1));
let end = start.min(computer.pools.pool.len().saturating_sub(1));
const POOL_BLOCKS_LIMIT: usize = 100;
let mut heights = Vec::with_capacity(POOL_BLOCKS_LIMIT);
for h in (0..=end).rev() {
if reader.get(h) == slug {
heights.push(h);
if heights.len() >= POOL_BLOCKS_LIMIT {
break;
}
}
}
let heights: Vec<usize> = computer
.pools
.pool_heights
.read()
.get(&slug)
.map(|pool_heights| {
let pos = pool_heights.partition_point(|h| h.to_usize() <= end);
let start = pos.saturating_sub(POOL_BLOCKS_LIMIT);
pool_heights[start..pos]
.iter()
.rev()
.map(|h| h.to_usize())
.collect()
})
.unwrap_or_default();
// Group consecutive descending heights into ranges for batch reads
let mut blocks = Vec::with_capacity(heights.len());