From 05403a913c6daf3566ba24d8fc7c6e1fc57cc795 Mon Sep 17 00:00:00 2001 From: pasta Date: Mon, 31 Aug 2026 16:59:28 +0200 Subject: [PATCH] perf(drive-abci): don't read every withdrawal document to build a debug log line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pool_withdrawals_into_transactions_queue_v1 fetches every withdrawal document the chain has ever produced, groups them by status and sorts each group, on any block with nothing queued — nearly every block — and then throws the result away unless debug logging is on. fetch_oldest_withdrawal_documents passes limit: None, and withdrawal documents are never removed, so the cost grows with chain history: measured at 4.8 ms per block by height 200,000 on mainnet and still climbing, against about 7 ms for everything else in a block put together. Do the work only when the line it feeds will be emitted. --- .../v1/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs index 8cdb4406ed7..4c58165dfe6 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs @@ -49,6 +49,16 @@ where .withdrawal_transactions_per_block_limit, "No queued withdrawal documents found to pool into transactions" ); + // Reading every withdrawal document the chain ever produced, only to + // count them for a log line. Withdrawal documents are never removed, + // so this grows without bound with chain history — measured at 4.8 ms + // a block by height 200,000 on mainnet, and it ran on every block + // that had nothing queued, which is nearly all of them. Do it only + // when the line it feeds will actually be emitted. + if !tracing::enabled!(tracing::Level::DEBUG) { + return Ok(()); + } + let all_documents = self .drive .fetch_oldest_withdrawal_documents(transaction, platform_version)?; @@ -57,7 +67,7 @@ where height = block_info.height, "No withdrawal documents found at all" ); - } else if tracing::enabled!(tracing::Level::DEBUG) { + } else { // Count documents by status let queued_count = all_documents .get(&(withdrawals_contract::WithdrawalStatus::QUEUED as u8))