Skip to content
Katabench
Try free

Topic

.NET Performance

Practical C# performance work: async behavior, allocations, garbage collection, algorithms, and the measurements that expose bottlenecks.

Practice this topic: C# coding challenges →

Try Two Sum → Free, no account needed

Latest articles

RSS feed →

25 articles

Binary search on the answer for shipping capacity

.NET Performance 7 min read

Find the smallest daily capacity that clears an ordered manifest. Trace the feasibility check, prove its greedy rule, and test both sides of the answer.

Read article →

Coin change with dynamic programming in C#

.NET Performance 7 min read

A greedy choice misses the best way to make eight. Build two dynamic programs for coin change and see why loop order changes the number of combinations.

Read article →

Counting inversions during merge sort

.NET Performance 7 min read

Measure how far a sequence is out of order by counting inversions. A worked merge shows how one comparison can count a whole run and why equal values need care.

Read article →

Monotonic stacks and the next warmer day

.NET Performance 7 min read

Find the first warmer day for every temperature in one pass. A C# stack of unresolved days handles equal readings and explains the linear time bound.

Read article →

Multi-source BFS for the nearest exit on a grid

.NET Performance 7 min read

Find the nearest exit for every room with one breadth-first search. Trace where two waves meet, handle unreachable rooms, and count the work in C#.

Read article →

Prefix sums for counting subarrays with a target sum

.NET Performance 7 min read

Count contiguous ranges with a given sum in one C# pass. Follow a signed ledger to see why duplicate prefixes, lookup order and 64-bit counts matter.

Read article →

Sliding windows with fixed and variable sizes

.NET Performance 7 min read

Use a rolling sum for fixed-width windows and frequency counts for variable ones. Trace when the left edge moves and how C# handles negative values.

Read article →

Two pointers for a pair sum in a sorted array

.NET Performance 7 min read

Trace a sorted two-sum search in C#, prove which pairs each move rules out, and catch the duplicate-index and overflow cases that break the proof.

Read article →

Weighted interval scheduling with a cleanup gap

.NET Performance 7 min read

Choose the most valuable compatible bookings for one room. Trace the scheduling table, find predecessors by finish time, and handle cleanup at the boundary.

Read article →

C# PriorityQueue: tie order, decrease-key and top-K

.NET Performance 9 min read

C# PriorityQueue is a quaternary heap with no stable tie order. A bounded top-K ran 100x faster than sorting on shuffled data and 7x slower on ascending.

Read article →

ArrayPool in C#: renting buffers without corrupting them

.NET Performance 9 min read

ArrayPool in C# removed a full GC every 24 calls at 128 KiB in one benchmark run. The rent and return pattern that keeps a shared buffer from corrupting data.

Read article →

HttpClient lifetime: socket exhaustion and stale DNS

.NET Performance 7 min read

Fix HttpClient lifetime mistakes by separating clients, handlers, and connections. Learn connection reuse, DNS refresh, and response ownership in .NET.

Read article →

IAsyncEnumerable in .NET: stream without hiding the cost

.NET Performance 8 min read

Use IAsyncEnumerable in .NET to process results as they arrive. Compare buffering, propagate cancellation, and keep resources alive until enumeration ends.

Read article →

System.Threading.Channels: bounded pipelines in .NET

.NET Performance 9 min read

System.Threading.Channels in .NET: why a bounded channel beats an unbounded queue, which BoundedChannelFullMode fits, and a consumer that drains safely.

Read article →

BenchmarkDotNet: measuring C# performance without fooling yourself

.NET Performance 8 min read

BenchmarkDotNet measures C# performance without the lies a Stopwatch tells: tiered JIT, dead-code elimination, and GC noise, plus how to read the results table.

Read article →

C# String Concatenation Performance, Measured

.NET Performance 8 min read

Choose between +, interpolation, StringBuilder, and direct writes in modern C#. Fix repeated copying, then verify the result with allocation benchmarks.

Read article →

CancellationToken in ASP.NET Core: stop doing work nobody wants

.NET Performance 7 min read

A disconnected client does not cancel your database query by itself. How RequestAborted flows through ASP.NET Core, EF Core, and HttpClient, and where it stops.

Read article →

C# async await mistakes that pass code review

.NET Performance 8 min read

The C# async await mistakes that pass code review: async void, fire and forget tasks, missing CancellationToken plumbing, and blocking on .Result.

Read article →

.NET garbage collection explained: what gen 0, 1, and 2 cost

.NET Performance 8 min read

.NET garbage collection explained: why most objects die young, what gen 0, 1, and 2 collections cost, and why the large object heap hurts latency.

Read article →

Sync over Async: Diagnose .NET Thread Pool Starvation

.NET Performance 9 min read

Learn how sync over async causes .NET Thread Pool starvation, spot it with dotnet-counters, capture blocking stacks, and fix ASP.NET Core latency.

Read article →

The LINQ query that ran twice: multiple enumeration and other deferred-execution traps

.NET Performance 7 min read

An IEnumerable isn't a list; it's a promise to do work later. Enumerate it twice and the work happens twice, including, with EF Core, the database query.

Read article →

The premature optimization myth: what Knuth actually said

.NET Performance 6 min read

The most-abused quote in software lets developers dodge performance entirely. Knuth's real argument, and why finding the critical 3% takes a trained instinct.

Read article →

Span<T>, Memory<T>, and stackalloc: when zero-allocation C# is worth it

.NET Performance 5 min read

Span<T> and stackalloc let you parse and slice without allocating, but they have real limits. When zero-allocation C# earns its keep and when it's overkill.

Read article →

The allocation tax: why correct, O(n) C# can still be slow

.NET Performance 6 min read

Correct, algorithmically optimal .NET code can still drag, because every needless allocation feeds the GC. How to spot and cut allocation pressure in C#.

Read article →

Big-O isn't interview trivia: where complexity actually bites in production

.NET Performance 6 min read

Big-O gets crammed for interviews and forgotten, but quadratic C# passes your tests and melts in prod. Where complexity bites and how to make it an instinct.

Read article →

Get new katas and .NET tips in your inbox

A short note when fresh kata land, plus the C# and performance tricks behind the grading. No spam, unsubscribe anytime.