From df21a24c53e4154c85c7440a5eab7dd3628ec5cb Mon Sep 17 00:00:00 2001 From: Brian Bland Date: Wed, 21 Oct 2026 14:38:30 -0700 Subject: [PATCH] perf(storage-overlay): register proof cursor metrics on first multiproof OverlayStateProvider::new and new_ref registered four groups of trie and hashed cursor metric handles with the global recorder on every call, so every BlockchainProvider::history_by_* call paid for them even when no multiproof was computed. Defer registration to the first multiproof for providers built outside a factory; factory providers keep sharing the factory's handles. Co-authored-by: Toshi --- crates/storage/storage-overlay/src/provider.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/storage/storage-overlay/src/provider.rs b/crates/storage/storage-overlay/src/provider.rs index 617becc7d8d..08a131c70e3 100644 --- a/crates/storage/storage-overlay/src/provider.rs +++ b/crates/storage/storage-overlay/src/provider.rs @@ -150,7 +150,7 @@ where Some(self.overlay_builder.clone()), Arc::clone(&self.state_trie_overlay_cache), self.metrics.clone(), - self.proof_cursor_metrics.clone(), + Some(self.proof_cursor_metrics.clone()), self.known_storage_roots.clone(), is_v2, )) @@ -174,7 +174,9 @@ where overlay_builder: Option>, state_trie_overlay_cache: StateTrieOverlayCache, metrics: OverlayStateProviderFactoryMetrics, - proof_cursor_metrics: ProofCursorMetrics, + /// Cursor metric handles for multiproof calculators. Providers built outside a factory + /// register them on their first multiproof, so opening a provider stays cheap. + proof_cursor_metrics: Option, /// Revealed storage roots from the reused sparse trie, shared across proof workers. known_storage_roots: Arc>, state_trie_overlay: OnceCell, @@ -274,7 +276,7 @@ where overlay_builder: Option>, state_trie_overlay_cache: StateTrieOverlayCache, metrics: OverlayStateProviderFactoryMetrics, - proof_cursor_metrics: ProofCursorMetrics, + proof_cursor_metrics: Option, known_storage_roots: Arc>, is_v2: bool, ) -> Self { @@ -793,7 +795,7 @@ where self.provider().tx(), input, self.is_v2, - self.proof_cursor_metrics.clone(), + self.proof_cursor_metrics.clone().unwrap_or_default(), self.known_storage_roots.clone(), ) };