Simple loop, big cost. Why it happensImmutable strings. Why it mattersMemory churn. Smart fixUse StringBuilder. var sb = new StringBuilder();
Category: C#
C# Exceptions Used for Flow Control
Code “works”, performance suffers. Why it happensExceptions are expensive. Why it mattersHidden CPU cost. Smart fixUse conditional checks instead.
C# LINQ Looks Clean but Runs Slow
Elegant code, heavy cost. Why it happensDeferred execution over large collections. Why it mattersHidden performance traps. Smart fixMaterialize results when reused. var list = query.ToList();
ASP.NET Core Startup Is Slow
Cold start hurts APIs. Why it happensHeavy dependency injection setup. Why it mattersFirst-request latency. Smart fixLazy-load expensive services. Lazy<MyService>
C# Value Types Copied More Than You Think
Structs feel lightweight. WhyPassed by value. TipUse in keyword. void Process(in MyStruct s) {}
C# Async Void Is Dangerous
Looks async, hides errors. WhyExceptions cannot be awaited. TipAvoid async void.
C# Foreach vs For Performance Difference
Looks same, runs different. WhyEnumerator allocations. TipUse for in hot paths. for (int i = 0; i < list.Count; i++) {}
.NET Core APIs Feel Slow Under Load
Low traffic, bad response. WhySynchronous IO usage. TipPrefer async methods. await stream.ReadAsync(buffer);
C# String Operations Hurt Performance
Heavy string manipulation. WhyImmutable strings. TipUse StringBuilder in loops. var sb = new StringBuilder();
C# DateTime Bugs Appear Across Servers
Same code, different results. WhyLocal time assumptions. TipAlways use UTC internally.
C# LINQ Queries Allocate Too Much
Elegant but costly. WhyDeferred execution misunderstood. TipMaterialize once when reused. var data = query.ToList();
C# Collections Resize Too Often
No errors, wasted cycles. WhyDefault capacity assumptions. TipInitialize collections with expected size. var list = new List<int>(capacity);
C# Exceptions Used for Control Flow
Works, but costs performance. WhyExceptions are expensive. TipUse conditionals for expected paths.
C# Async Code Causes Thread Pool Pressure
Async everywhere, still bottlenecks. WhyCPU-bound work mixed with async I/O. TipIsolate CPU-heavy tasks.
C# Collections Hurt Performance in Hot Paths
Correct code, slow execution. WhyUnnecessary allocations. TipReuse collections when possible.
C# Async Code Hides Blocking Calls
Looks async, behaves sync. WhyBlocking APIs inside async flows. await Task.Delay(1); // not Thread.Sleep
C# Objects Live Longer Than Expected
Memory grows slowly. WhyStatic references prevent GC. TipAvoid static state for request-based data.
C# LINQ Is Not Free
Readable code hides allocations. WhyEnumerators and deferred execution. Tip Use LINQ for clarity, loops for hot paths.
C# Structs Hurt Performance When Misused
Structs feel fast, sometimes aren’t. WhyLarge structs copy frequently. Tip Use structs only for small, immutable data.
C# Async Code Still Causes High CPU
Async everywhere, still heavy. WhyCPU-bound work inside async flows. Tip Separate CPU-bound and I/O-bound tasks.
C# Logging Produces Too Much Noise
Logs exist, signal lost. WhyNo log level strategy. Tip Log intent, not execution.
C# Dependency Injection Containers Slow Startup
Large apps feel heavy. WhyOver-registration and reflection. Tip Avoid unnecessary service lifetimes.
C# Records Used Where Classes Fit Better
Looks modern, causes issues. WhyRecords emphasize immutability and value semantics. Tip Use records intentionally, not everywhere.
C# LINQ Looks Clean but Allocates Heavily
Readable code, hidden cost. WhyDeferred execution and allocations. Fix Use loops for hot paths.
C# Value Types Cause Hidden Copies
Structs feel fast… sometimes aren’t. WhyLarge structs are copied frequently. Fix Pass large structs by in reference.
C# Async Code Still Blocks Threads
Async keyword isn’t magic. WhyBlocking calls inside async flows. Fix Never mix Task.Run with blocking I/O.
C# Exceptions Used as Flow Control
Code works… but crawls. WhyExceptions are expensive. Fix Use conditional logic for expected paths.
C# String Concatenation Hurts Performance in Loops
Looks harmless, isn’t. WhyImmutable strings cause repeated allocations. Fix Use StringBuilder for iterative builds.
C# lock Statements Reduce Scalability
Code is safe but slow. WhyThreads block instead of cooperating. Fix Prefer concurrent collections when possible.
C# Static Constructors Break Startup
App fails before logging. WhyExceptions thrown too early. FixMove logic out of static constructors.

