performance-optimization

Profiles, caches, and optimizes .NET application performance using monitoring, caching, and query tuning patterns.

Updated Aug 10, 2025
One-click install
npx skills add https://github.com/afonsoft/ai-studio-workspace --skill performance-optimization-afonsoft
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: performance-optimization
Source: https://github.com/afonsoft/ai-studio-workspace/tree/main/agents/skills/performance-optimization
Command: npx skills add https://github.com/afonsoft/ai-studio-workspace --skill performance-optimization-afonsoft

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? .NET applications often suffer from slow response times, memory leaks, and inefficient database queries that are hard to diagnose and fix without structured profiling and optimization strategies. ## Core Features & Use Cases - Performance Profiling: Built-in performance counters, memory monitors, and request middleware to identify CPU, memory, and I/O bottlenecks. - Caching Strategies: Multi-level caching (memory + distributed), cache-aside pattern, and cache invalidation for faster data access. - Database & Memory Optimization: Optimized repository patterns, compiled EF Core queries, batch processing, object pooling, and async best practices. - Use Case: When an ASP.NET Core API endpoint responds slowly under load, use this Skill to add request performance middleware, identify the slow database query, apply a multi-level cache, and verify improvement with health checks. ## Quick Start Analyze my .NET application's performance bottlenecks and implement caching and query optimizations for the slow endpoints.

Frequently Asked Questions about performance-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I profile performance in a .NET application?▼

Use a PerformanceCounter class with IDisposable timers to measure operation durations and counts, combined with request middleware that logs per-endpoint response times. Memory monitors using GC.GetTotalMemory track allocation patterns and collection counts.

How to implement multi-level caching in ASP.NET Core?▼

Combine IMemoryCache as a fast L1 cache with IDistributedCache as an L2 fallback. Check memory first, then distributed cache, and populate memory on L2 hits to reduce serialization overhead on subsequent requests.

What is the cache-aside pattern in .NET?▼

Cache-aside checks the cache before loading data from the source, then stores the result in cache on a miss. It is implemented with a generic service wrapping ICacheService and a data loader delegate, with explicit invalidation on writes.

Does Entity Framework Core support compiled queries for performance?▼

Yes, EF.CompileAsyncQuery creates precompiled query delegates that skip repeated query translation, reducing overhead for frequently executed queries. Combine with AsNoTracking for read-only scenarios to further cut change-tracking costs.

Why does my .NET application have high memory usage?▼

High memory usage often comes from excessive allocations, unbounded collections, or missing object reuse. Use object pooling for frequently created objects like StringBuilder, stream large datasets with IAsyncEnumerable, and monitor GC collection counts.

When should I use batching instead of Task.WhenAll for async operations?▼

Use batching when processing large item sets to avoid overwhelming downstream services or exhausting connection pools. Chunk items into groups, await each batch with Task.WhenAll, and add small delays between batches to throttle load.