Skip to content

Commit

Permalink
Avoid potentially expensive computations when logging is disabled (re…
Browse files Browse the repository at this point in the history
  • Loading branch information
akosthekiss authored Nov 24, 2023
1 parent 4657d03 commit 437bea7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion picire/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ def reduce(src, *,
# (minus src, as that parameter can be arbitrarily large)
args = locals().copy()
del args['src']
logger.info('Reduce session starts\n%s', indent(pretty_str(args), '\t'))
if logger.isEnabledFor(logging.INFO):
logger.info('Reduce session starts\n%s', indent(pretty_str(args), '\t'))

cache = cache_class(**cache_config) if cache_class else None

Expand Down
12 changes: 9 additions & 3 deletions picire/dd.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def _lookup_cache(self, config, config_id):
is disabled, PASS or FAIL otherwise.
"""
cached_result = self._cache.lookup(config)
if cached_result is not None:

if cached_result is not None and logger.isEnabledFor(logging.DEBUG):
logger.debug('\t[ %s ]: cache = %r', self._pretty_config_id(self._iteration_prefix + config_id), cached_result.name)

return cached_result
Expand All @@ -200,9 +201,14 @@ def _test_config(self, config, config_id):
"""
config_id = self._iteration_prefix + config_id

logger.debug('\t[ %s ]: test...', self._pretty_config_id(config_id))
if logger.isEnabledFor(logging.DEBUG):
pretty_config_id = self._pretty_config_id(config_id)
logger.debug('\t[ %s ]: test...', pretty_config_id)

outcome = self._test(config, config_id)
logger.debug('\t[ %s ]: test = %r', self._pretty_config_id(config_id), outcome.name)

if logger.isEnabledFor(logging.DEBUG):
logger.debug('\t[ %s ]: test = %r', pretty_config_id, outcome.name)

if 'assert' not in config_id:
self._cache.add(config, outcome)
Expand Down

0 comments on commit 437bea7

Please sign in to comment.