From 6b585eec4de6d7552f5696d07e3fc60c9e6b12a7 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sat, 28 Mar 2026 20:02:08 +0100 Subject: [PATCH] perf: use FastInstant for remaining metrics timing Replace std::time::Instant with quanta-based FastInstant (TSC on x86) in metrics and timing code that was still using the slower clock_gettime syscall. --- crates/cli/commands/src/db/checksum/rocksdb.rs | 3 ++- crates/cli/commands/src/download/manifest_cmd.rs | 3 ++- crates/cli/commands/src/stage/run.rs | 3 ++- .../tree/src/tree/payload_processor/preserved_sparse_trie.rs | 3 ++- crates/net/network/src/metrics.rs | 2 +- crates/rpc/rpc-builder/src/metrics.rs | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/cli/commands/src/db/checksum/rocksdb.rs b/crates/cli/commands/src/db/checksum/rocksdb.rs index b30ddb87cf9..d2d06d72511 100644 --- a/crates/cli/commands/src/db/checksum/rocksdb.rs +++ b/crates/cli/commands/src/db/checksum/rocksdb.rs @@ -8,8 +8,9 @@ use reth_db::{tables, DatabaseEnv}; use reth_db_api::table::Table; use reth_db_common::DbTool; use reth_node_builder::NodeTypesWithDBAdapter; +use reth_primitives_traits::FastInstant as Instant; use reth_provider::RocksDBProviderFactory; -use std::{hash::Hasher, time::Instant}; +use std::hash::Hasher; use tracing::info; /// RocksDB tables that can be checksummed. diff --git a/crates/cli/commands/src/download/manifest_cmd.rs b/crates/cli/commands/src/download/manifest_cmd.rs index 0dcdca1504e..acd8509ce8b 100644 --- a/crates/cli/commands/src/download/manifest_cmd.rs +++ b/crates/cli/commands/src/download/manifest_cmd.rs @@ -3,9 +3,10 @@ use clap::Parser; use eyre::{Result, WrapErr}; use reth_db::{mdbx::DatabaseArguments, open_db_read_only, tables, Database}; use reth_db_api::transaction::DbTx; +use reth_primitives_traits::FastInstant as Instant; use reth_stages_types::StageId; use reth_static_file_types::DEFAULT_BLOCKS_PER_STATIC_FILE; -use std::{path::PathBuf, time::Instant}; +use std::path::PathBuf; use tracing::{info, warn}; /// Generate modular chunk archives and a snapshot manifest from a source datadir. diff --git a/crates/cli/commands/src/stage/run.rs b/crates/cli/commands/src/stage/run.rs index 9c0c8bbc32f..817849dc216 100644 --- a/crates/cli/commands/src/stage/run.rs +++ b/crates/cli/commands/src/stage/run.rs @@ -28,6 +28,7 @@ use reth_node_metrics::{ server::{MetricServer, MetricServerConfig}, version::VersionInfo, }; +use reth_primitives_traits::FastInstant as Instant; use reth_provider::{ ChainSpecProvider, DBProvider, DatabaseProviderFactory, StageCheckpointReader, StageCheckpointWriter, @@ -40,7 +41,7 @@ use reth_stages::{ }, ExecInput, ExecOutput, ExecutionStageThresholds, Stage, StageExt, UnwindInput, UnwindOutput, }; -use std::{any::Any, net::SocketAddr, sync::Arc, time::Instant}; +use std::{any::Any, net::SocketAddr, sync::Arc}; use tokio::sync::watch; use tracing::*; diff --git a/crates/engine/tree/src/tree/payload_processor/preserved_sparse_trie.rs b/crates/engine/tree/src/tree/payload_processor/preserved_sparse_trie.rs index bfc3430fc61..fc830a4b359 100644 --- a/crates/engine/tree/src/tree/payload_processor/preserved_sparse_trie.rs +++ b/crates/engine/tree/src/tree/payload_processor/preserved_sparse_trie.rs @@ -2,8 +2,9 @@ use alloy_primitives::B256; use parking_lot::Mutex; +use reth_primitives_traits::FastInstant as Instant; use reth_trie_sparse::{ConfigurableSparseTrie, SparseStateTrie}; -use std::{sync::Arc, time::Instant}; +use std::sync::Arc; use tracing::debug; /// Type alias for the sparse trie type used in preservation. diff --git a/crates/net/network/src/metrics.rs b/crates/net/network/src/metrics.rs index 1b3fdbfaa46..fbbebaddc93 100644 --- a/crates/net/network/src/metrics.rs +++ b/crates/net/network/src/metrics.rs @@ -293,7 +293,7 @@ pub struct TransactionFetcherMetrics { #[macro_export] macro_rules! duration_metered_exec { ($code:expr, $acc:expr) => {{ - let start = std::time::Instant::now(); + let start = reth_primitives_traits::FastInstant::now(); let res = $code; diff --git a/crates/rpc/rpc-builder/src/metrics.rs b/crates/rpc/rpc-builder/src/metrics.rs index 56bb9a313c9..5bd2ab23f2f 100644 --- a/crates/rpc/rpc-builder/src/metrics.rs +++ b/crates/rpc/rpc-builder/src/metrics.rs @@ -8,13 +8,13 @@ use reth_metrics::{ metrics::{Counter, Histogram}, Metrics, }; +use reth_primitives_traits::FastInstant as Instant; use std::{ collections::HashMap, future::Future, pin::Pin, sync::Arc, task::{Context, Poll}, - time::Instant, }; use tower::Layer;