Skip to content

perf: guard debug logging to avoid string allocations#4682

Merged
thomhurst merged 1 commit intomainfrom
perf/guard-debug-logging
Feb 6, 2026
Merged

perf: guard debug logging to avoid string allocations#4682
thomhurst merged 1 commit intomainfrom
perf/guard-debug-logging

Conversation

@thomhurst
Copy link
Owner

Summary

  • Add `IsDebugEnabled` property to `TUnitFrameworkLogger`
  • Wrap all `LogDebugAsync` calls in hot paths (ConstraintKeyScheduler, TestScheduler) with `if (_logger.IsDebugEnabled)` guards
  • Prevents interpolated string allocations when debug logging is disabled (the common case)
  • For 10,000+ tests, this avoids 20,000+ unnecessary string allocations in the scheduler alone

Test plan

  • Verify debug logging still works when enabled
  • Verify no functional changes when logging is disabled
  • Run full engine test suite

🤖 Generated with Claude Code

Add IsDebugEnabled property and wrap all LogDebugAsync calls in hot paths
with a check. This prevents interpolated string allocations when debug
logging is disabled, which is the common case in production.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Contributor

claude bot commented Feb 6, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

This PR is a clean performance optimization that aligns perfectly with CLAUDE.md Rule 4 (Performance First). The IsDebugEnabled property logic is correct (mathematically equivalent to IsEnabled(LogLevel.Debug)), and the guard pattern effectively prevents unnecessary string interpolations in hot paths when debug logging is disabled.

The changes are in the unified execution path after metadata collection, so Rule 1 (Dual-Mode) does not apply. All 13 guarded log calls follow a consistent mechanical pattern with no logic errors or side effects.

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.

1 participant