The hidden killer: rehashing.
When capacity grows, the dictionary reallocates everything.
✅ Fix
Always pre-size:
var dict = new Dictionary<int, User>(expectedCount);
Real impact
-
Eliminates random latency spikes
-
Crucial in hot paths
Daily micro-tips for C#, SQL, performance, and scalable backend engineering.
The hidden killer: rehashing.
When capacity grows, the dictionary reallocates everything.
Always pre-size:
var dict = new Dictionary<int, User>(expectedCount);
Real impact
Eliminates random latency spikes
Crucial in hot paths