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
No articles match. Try fewer words or a different term. Search all articles
Binary search on the answer for shipping capacity
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#
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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
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 →