Skip to content

Commit e9ec102

Browse files
CopilotSteake
andcommitted
Optimize trace logging to avoid unnecessary hex encoding
- Only compute hex encoding when trace level is enabled - Addresses code review feedback for performance optimization Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
1 parent b8d4a76 commit e9ec102

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

  • crates/bitcell-state/src

crates/bitcell-state/src/lib.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ impl StateManager {
100100
// Fallback to storage if available
101101
if let Some(storage) = &self.storage {
102102
if let Ok(Some(account)) = storage.get_account(pubkey) {
103-
tracing::trace!(
104-
pubkey = %hex::encode(&pubkey),
105-
"Loaded account from storage (cache miss)"
106-
);
103+
if tracing::enabled!(tracing::Level::TRACE) {
104+
tracing::trace!(
105+
pubkey = %hex::encode(&pubkey),
106+
"Loaded account from storage (cache miss)"
107+
);
108+
}
107109
return Some(account);
108110
}
109111
}
@@ -155,10 +157,12 @@ impl StateManager {
155157
// Fallback to storage if available
156158
if let Some(storage) = &self.storage {
157159
if let Ok(Some(bond)) = storage.get_bond(pubkey) {
158-
tracing::trace!(
159-
pubkey = %hex::encode(&pubkey),
160-
"Loaded bond from storage (cache miss)"
161-
);
160+
if tracing::enabled!(tracing::Level::TRACE) {
161+
tracing::trace!(
162+
pubkey = %hex::encode(&pubkey),
163+
"Loaded bond from storage (cache miss)"
164+
);
165+
}
162166
return Some(bond);
163167
}
164168
}

0 commit comments

Comments
 (0)