I'm a junior developer working on a .NET line-of-business application. We have some code that checks to see if a Dictionary has a key, and if it does, it retrieves the value:
if (_dict.ContainsKey(key)) return _dict[key];
That code is slightly inefficient. It would be faster to access the Dictionary only once, like this:
if (_dict.TryGetValue(key, out var value)) return value;
We have around 300 instances of code like this. If your codebase was like this and you were a decision-maker, would you do anything to fix those instances? If so, would you do it all in one go, or would you just flag it as something to fix over time?
I know the conventional wisdom for fixing performance problems is "profile it, and fix the bottlenecks." But what about cases like this, where the fix is an objective improvement, and the problems are so spread out through the system that none of them are likely to show up as red flags in a profile?
submitted by /u/YakaryBovine
[link] [comments]
from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/MXTlcdh