jadepy: avoid expensive message formatting for lines that won't be logged
What changed, and why it matters
This commit is a minor performance optimization in the Python library that talks to the Jade hardware wallet. It prevents the code from building detailed debug log messages when debug logging is turned off. There is no security issue here.
No security action needed. Treat as a normal performance improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change wraps two logger.debug() calls with if logger.isEnabledFor(logging.DEBUG): guards. Previously, the f-string argument (which calls _hexlify() on the full request/response CBOR message) was always evaluated, even when DEBUG logging was disabled. Now it is only evaluated when DEBUG logging is actually enabled. This is a standard logging performance improvement and does not alter program behavior, output, or security posture.
Changed components
jadepy/jade.pyInspect captured patch +4 / −2
diff --git a/jadepy/jade.py b/jadepy/jade.py
index 113576d..6ade672 100644
--- a/jadepy/jade.py
+++ b/jadepy/jade.py
@@ -2200,7 +2200,8 @@ class JadeInterface:
"""
dump = cbor.dumps(request)
logger.info(f'Sending {request["method"]} request {request["id"]} length {len(dump)}')
- logger.debug(f'Sending: {_hexlify(request)}')
+ if logger.isEnabledFor(logging.DEBUG):
+ logger.debug(f'Sending: {_hexlify(request)}')
return dump
def write(self, bytes_):
@@ -2271,7 +2272,8 @@ class JadeInterface:
# A message response (to a prior request)
if 'id' in message:
logger.info(f'Received reply {message["id"]}')
- logger.debug(f'Received: {_hexlify(message)}')
+ if logger.isEnabledFor(logging.DEBUG):
+ logger.debug(f'Received: {_hexlify(message)}')
return message
# A log message - handle as normal
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.