Skip to content

Comments

Performance: don't use f-strings in debug prints#606

Merged
niknetniko merged 1 commit intomasterfrom
perf/debug-f-string
Jan 24, 2026
Merged

Performance: don't use f-strings in debug prints#606
niknetniko merged 1 commit intomasterfrom
perf/debug-f-string

Conversation

@bmesuere
Copy link
Member

Many of the debug prints contained f-strings. While these are easy to read, the string is created even if the logger never needs the actual string because of the debug level. Switching to lazy string formatting saves some work and garbage collection if debugging is not enabled.

Unexpectedly, performance gains are measurable and up to 5% when measuring the total run time of a single exercise (21.6s -> 20.5s, average over 10 runs).

@bmesuere bmesuere changed the title Don't use f-strings in debug prints Performance: don't use f-strings in debug prints Jan 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes debug logging performance by converting f-string formatting to lazy string formatting. The change prevents string construction when debug logging is disabled, resulting in measurable performance improvements (up to 5% reduction in total run time).

Changes:

  • Replaced f-string formatting in debug log statements with printf-style %s placeholders
  • Moved variables from inline f-string expressions to separate logger arguments
  • Applied changes consistently across 10 files covering parsing, execution, evaluation, and configuration modules

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tested/parsing.py Converted 4 debug log statements in type structure functions
tested/oracles/programmed.py Converted 2 debug log statements including multi-line oracle parameter logging
tested/judge/utils.py Converted 2 debug log statements for file copying operations
tested/judge/execution.py Converted 4 debug log statements for execution, dependencies, and file operations
tested/judge/evaluation.py Converted 1 debug log statement for testcase evaluation
tested/judge/core.py Converted 5 debug log statements for worker execution and file generation
tested/judge/compilation.py Converted 1 debug log statement for compilation dependencies
tested/judge/collector.py Converted 3 debug log statements for command and stack management
tested/internationalization/init.py Converted 1 debug log statement for locale changes
tested/configs.py Converted 2 multi-line debug log statements for language detection

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@niknetniko niknetniko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice speed up for no changes at all.

@niknetniko niknetniko merged commit b59c249 into master Jan 24, 2026
13 checks passed
@niknetniko niknetniko deleted the perf/debug-f-string branch January 24, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants