In the current project I am working on I have come across a piece of code which seems to be overblown. I considered rewriting it to avoid more objects in memory than need be, and had trouble making a decision about whether the performance benefits from refactoring would be worth the time, and whether the current design will impact performance at any stage through out the application lifetime and therefore need to be changed.
I realised I did not have the knowledge to answer these questions. What knowledge do I need to make accurate assessments of the performance of a code design? Does anyone know any good resources on C#/Java internal workings that would help my understanding?
There is a huge amount of information out there, particularly by researching on MSDN – but…
The only way you’ll really know whether you need to take the time to refactor is to profile this code. If it’s bloated in terms of memory or run times, you may want to take the time to refactor it. If it runs quickly, and doesn’t actually take as much memory as you expect, the gains may not be worth the effort.
Code design alone is never enough – most of the time, if you’re projecting a performance pattern based off a design, your projection will be wrong. Yes, there are cases where code is obviously horribly designed, but most of the time, the (small) part that will be the actual problem is not the part where you expect the problem to exist – it’s often some other small piece of code somewhere you never expect…