Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
dotnet-simformsolutions avatar

Csharp Perf Analysis

  • 1 installs
  • Updated July 30, 2026
  • dotnet-simformsolutions/ai-dotnet-solution-scaffolder

Detects inefficient C# patterns like string concatenation in loops, boxing, sync-over-async, excessive allocations, and reflection in hot paths.

About

Scans C# code for performance anti-patterns including LINQ abuse, blocking on async, boxing, and missing IDisposable. A developer uses it when reviewing C# for performance bottlenecks and memory issues.

  • Detects sync-over-async and boxing in hot paths
  • Flags string and LINQ allocation anti-patterns

Csharp Perf Analysis by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #121 of 153 .NET & C# skills by installs in the Skillselion catalog
  • Data as of Jul 31, 2026 (Skillselion catalog sync)
npx skills add https://github.com/dotnet-simformsolutions/ai-dotnet-solution-scaffolder --skill csharp-perf-analysis

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
Last updatedJuly 30, 2026
Repositorydotnet-simformsolutions/ai-dotnet-solution-scaffolder

What it does

Detects inefficient C# patterns like string concatenation in loops, boxing, sync-over-async, excessive allocations, and reflection in hot paths.

Files

SKILL.mdMarkdownGitHub ↗

C# Performance Analysis

When to Use

  • Analyzing C# files for performance issues
  • Detecting memory allocation problems
  • Finding synchronous blocking in async code
  • Identifying reflection or boxing in hot paths
  • Code review for performance anti-patterns

Analysis Procedure

1. Scan C# Files

Use grep_search or semantic_search to find C# files in the project:

  • Search for *.cs files
  • Prioritize files in hot paths (controllers, repositories, services, background workers)

2. Pattern Detection

For each C# file, scan for these anti-patterns:

String Operations
  • String concatenation in loops (for/foreach/while containing + operator on strings)
  • Multiple string concatenations without StringBuilder
  • Pattern: str += something inside loop body
LINQ Abuse
  • .ToList() or .ToArray() before further filtering
  • Example: collection.ToList().Where(x => x.Condition) → should be collection.Where(x => x.Condition).ToList()
  • Multiple enumerations of IEnumerable without caching
Synchronous Over Async (Blocking)
  • .Result or .GetAwaiter().GetResult() on Task
  • .Wait() on Task in async contexts
  • Look for these in async methods or methods called from async contexts
  • Deadlock risk in ASP.NET contexts
Boxing/Unboxing
  • Value types in collections that expect object (non-generic collections)
  • ArrayList, Hashtable instead of List<T>, Dictionary<TKey, TValue>
  • String interpolation with value types in hot paths (consider avoiding in tight loops)
Memory Allocations
  • new keyword inside tight loops (millions of iterations)
  • Closures capturing variables in hot paths
  • Large value types being copied repeatedly
  • Array reallocations (use List<T> with initial capacity)
Resource Management
  • Classes implementing IDisposable without using statement or proper disposal
  • File handles, database connections, HTTP clients not properly disposed
  • Missing ConfigureAwait(false) in library code
Time Operations
  • DateTime.Now in performance-critical code → use DateTime.UtcNow (faster, no timezone conversion)
  • Repeated calls to DateTime.Now in same method → cache the value
Reflection
  • Type.GetType(), MethodInfo.Invoke(), Activator.CreateInstance() in loops
  • Reflection in hot paths without caching
  • Consider compiled expressions or source generators
Collection Inefficiency
  • Using List<T> with .Contains() for membership testing → use HashSet<T>
  • First() or Single() without predicate followed by check → use FirstOrDefault(predicate)
  • Linear search (foreach + if) when dictionary lookup available

3. Load Anti-Pattern Reference

When you find patterns, consult csharp-antipatterns.md for:

  • Detailed explanation of why the pattern is problematic
  • Code examples showing bad vs good implementations
  • Performance impact estimates

4. Rank Findings

Assign severity:

  • Critical: Blocking operations in async code, resource leaks
  • High: String concat in loops, N+1 database patterns via code, excessive allocations in tight loops
  • Medium: Boxing, suboptimal LINQ, reflection in moderate-use paths
  • Low: DateTime.Now instead of UtcNow, minor collection inefficiencies

5. Output Format

For each finding:

**[Severity]** Issue in [file.cs](file.cs#L123-L125)

**Problem**: Brief description of the anti-pattern

**Impact**: Performance implication (e.g., "Allocates N string objects per loop iteration")

**Fix**: 
\`\`\`csharp
// Replace this:
string result = "";
foreach (var item in items)
{
    result += item.ToString();
}

// With this:
var sb = new StringBuilder();
foreach (var item in items)
{
    sb.Append(item.ToString());
}
string result = sb.ToString();
\`\`\`

**Estimated Improvement**: "Reduces allocations from O(N²) to O(N)"

Auto-Fix Capability

You can automatically fix these patterns when requested:

  • ✅ String concatenation → StringBuilder
  • .Result / .Wait()await (ensure method is async)
  • ✅ Generic collections for non-generic ones
  • ✅ Add using statements for IDisposable
  • DateTime.NowDateTime.UtcNow
  • ✅ Add ConfigureAwait(false) in library code
  • ❌ Architectural changes (require manual review)

Examples

Quick Scan Command

// Search for sync-over-async anti-patterns
grep_search(".Result|.Wait\\(\\)|.GetAwaiter\\(\\).GetResult\\(\\)", isRegexp: true, includePattern: "**/*.cs")

Pattern Recognition

Look for these code patterns: 1. Loop + string concatenation 2. async method with .Result or .Wait() 3. IDisposable type without using 4. List<T>.Contains() in a loop 5. new inside for loop with large iteration count

Notes

  • Always consider the execution frequency (hot path vs cold path)
  • Profile before and after fixes when possible
  • Some patterns are acceptable in cold paths (startup code, infrequent operations)
  • Document assumptions about frequency if not obvious from code

Related skills

.NET & C#backend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.