Instruction file imported from zNatix/pr-reviewer-agent (
.github/instructions/performance-warnings.instructions.md). Copyright stays with the author.
Performance Standards — Warnings
🟡 Warning
Collections
- Prefer
IEnumerable<T>for return types when callers don't need list/index access - Use
ICollection<T>orIList<T>only when mutation is required by callers - Dictionary lookups:
TryGetValue()instead ofContainsKey()+ indexer
LINQ
FirstOrDefault()+ null check overSingle()when duplicates are possible.Count() > 0→.Any()- Multiple
.Where()calls can often be merged into one - Avoid
.OrderBy().OrderBy()— the second overwrites the first
Logging
- Use
LoggerMessagesource generators for high-performance logging (C# 12+) - Use structured logging:
_logger.LogInformation("Processing {OrderId}", id) - Never string interpolation in log messages
- Guard expensive log parameter evaluation with
_logger.IsEnabled(LogLevel.Debug)
Concurrency & Resource Disposal
- Types implementing both
IDisposableandIAsyncDisposablemust be disposed withawait usingwhen used in async code - Flag
using(sync) on types that implementIAsyncDisposablein async methods - Use
ConcurrentDictionary<TKey,TValue>instead ofDictionary+ manual locking - Flag sync-over-async on hot paths — this causes thread pool starvation under load
- Use
Task.WhenAllfor independent parallel async operations, not sequential awaits Parallel.ForEachwith async bodies → flag; useTask.WhenAllorParallel.ForEachAsync(.NET 6+)
Resilience
HttpClientcalls in production code without retry/fallback policy → flag (use Polly orMicrosoft.Extensions.Resilience)- Retry logic without exponential backoff and jitter
- No timeout on
HttpClientrequests (default 100s is too high for most service-to-service calls) - Missing circuit breaker pattern on critical external dependencies
Rate Limiting
- ASP.NET Core endpoints exposed publicly without
[EnableRateLimiting]or rate limiting middleware → flag - Missing rate limiting on authentication endpoints (login, token refresh) — brute force vector