agentleFS
RuneStone-TechRuneStone-Tech/optimize-anything/skills/backend/csharp/SKILL.md

csharp-optimizer

Skill1 starsChanged 8 days agoMITView on GitHub

Audit and optimize C#/.NET 10 LTS services and apps (C# 14, ASP.NET Core, EF Core, NativeAOT/trimming) for target-framework/EOL risk, allocations and GC, async/await traps, EF Core N+1 and tracking, HttpClient/DI lifetimes, nullable/analyzer quality, and profiling, with real before/after measurement. Always produces a written findings report and a fix plan for approval before touching code. Use this whenever the user mentions slow .NET, .NET 8/9 to 10, C# 14, GC pressure, async deadlocks, `.Result`/`.Wait()`, EF Core N+1, NativeAOT/trimming, Server GC, or "optimize my C# app" -- even if they never say audit or optimize.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run python <skill-dir>/scripts/audit.py <project-root> -- static scan of build files and sources for EOL target frameworks, allocations/GC, …

    line 15
  2. Very specific:

    Read references/tooling.md once: what can be measured here.

    line 17
  3. Very specific:

    Use plan mode: EnterPlanMode (load with ToolSearch if deferred), write the plan, present with ExitPlanMode.

    line 39

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

C# Optimizer

.NET 10 LTS (10.0.14) is the current production target; .NET 8 and .NET 9 reach end of support on November 10, 2026. C# 14 ships with .NET 10. Optimization is allocation/GC behavior, async correctness, EF Core query shape and publish settings (AOT/trim/R2R), not micro-benchmarks.

Workflow

1. Scope (quick)

  • Find the project root and record the toolchain: .NET target framework/SDK, C# language version, project type (ASP.NET Core/worker/desktop), GC/publish settings, EF Core/ORM, HttpClient/DI and deployment model.
  • Run python <skill-dir>/scripts/audit.py <project-root> -- static scan of build files and sources for EOL target frameworks, allocations/GC, async blocking, EF Core N+1/tracking, HttpClient/DI lifetimes, nullable/analyzer gaps, AOT/trimming issues, with file:line evidence. Use --json to post-process.
  • Classify the pain: throughput/latency, memory growth, CPU saturation, concurrency/correctness, I/O or database cost, build/startup, or safety/maintenance. Ask which hurts if unclear.
  • Read references/tooling.md once: what can be measured here.

2. Audit

The script finds cheap leads; you find the rest by reading the hot path and the build. Read the build manifest, entrypoint, the 3-5 hot functions/endpoints and the data layer. Load only what applies:

| Build, runtime and publish | references/build-runtime.md | | Memory and concurrency | references/memory-concurrency.md | | I/O, EF Core and data | references/io-data.md | | Safety and quality | references/safety-quality.md | | Measurement | references/tooling.md |

Measure, never guess. Build with production settings, run with production data/load, and profile that. Debug builds, dev servers and a single request are not evidence. Take a profile before micro-optimizing and a heap/allocator snapshot before raising limits.

Mark each finding Confirmed (profile/load/code evidence) or Suspected (needs measuring).

3. Report

Fill assets/report-template.md, save it as C#_OPTIMIZATION_REPORT.md in the project root, and show the user. Five-line summary, findings table by impact/effort, then per-finding detail (evidence, why it hurts, fix, risk, behavior impact). Group near-duplicates.

4. Plan -- then stop for approval

Use plan mode: EnterPlanMode (load with ToolSearch if deferred), write the plan, present with ExitPlanMode; if unavailable show it in chat and wait for an explicit "go". Structure:

  1. Quick wins -- build flags, missing indexes/caching, timeouts/pool limits, avoidable allocations/copies, sync I/O in hot paths, missing await/join, safer bounds checks, log noise, config limits. Low risk.
  2. Structural -- bound concurrency, batch N+1, stream large payloads, change data structures/ownership, split hot paths, cache correctly, connection/worker pools, graceful shutdown, observability. Name each behavior change.
  3. Heavy -- language/toolchain major upgrade, runtime/GC change, framework/ORM swap, architecture change, AOT/trimming, database migration. Separately approved. Each step: files touched, expected effect, how to verify, how to roll back.

5. Fix

Only approved items, in small groups. After each: build with production flags, run the test suite, and re-run the same benchmark/profile. A break must trace to one change. Do not mix a toolchain major upgrade with optimization edits. If a change alters ownership, concurrency, API/DB semantics or failure behavior, stop and ask.

6. Verify and wrap up

Re-measure the same workload and data: throughput and p50/p95/p99, CPU, RSS/heap, allocations/GC, I/O, error rate, build time and binary/image size. State plainly what could not be measured. End with deferred items and one suggested next step.

Principles

  • .NET 10 LTS is the target. .NET 8/9 support ends November 10, 2026.
  • Async all the way. .Result/.Wait() and async void are correctness bugs, not style.
  • Allocations are the GC. Span/ArrayPool/StringBuilder and fewer LINQ chains reduce pauses.
  • Query shape beats ORM tuning. Projection, no-tracking, split queries and indexes.
  • Measure Release/publish. Debug builds and IIS Express are not production.

Docs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.