I am working on a program which does a lot of manipulation on objects; creating, deleting, dynamic_cast-ing them, shuffling around pointers, comparing contents etc. Most of these objects are at least 40 bytes (up to ~90 bytes), and there may be upwards of 10,000 of them in memory at once.
What I’m trying to determine is whether I should bother trying to decrease their size. I could profile constructors, new, delete, etc. However, I am lead to believe that the most important performance hit from large objects is from cache unfriendliness. Is there a way to determine the contribution of the size of objects on the number of cache misses that happen?
PS: I imagine excessive use of dynamic_cast also affects performance. However this is much easier to diagnose.
EDIT: I know that it’s useless to optimize without profiling. What I am asking is how do I determine, from profiling, if it is a problem. Is it possible that the penalty is distributed throughout the code such that standard profiling tools won’t be helpful?
You are approaching it the way most people do, until they cross the line and Get It.
As Paul R said in his comment, don’t just guess.
To put it another way, your entire approach should be centered around diagnosis.
Otherwise you are like a medical doctor who treats people by assuming that everyone is alike, and what works for the goose must work for the gander.
Does that mean cache-related issues are not a problem?
Does that mean memory-allocation issues are not a problem?
Not necessarily.
It means they are guesses and they might be problems, but there almost certainly are other problems that nobody could guess in advance.
There’s an example discussed here where six (6) different problems were found and fixed, having a range of sizes that just happen to add up to nearly all the time, the way a bunch of coins of different sizes can add up to a dollar.
Sure, one of them was memory allocation, but only one.
If you had fixed the memory allocation problem and stopped there, or that plus some other preconceived problem and stopped there, how much speedup would you have gotten?
A fraction of the speedup ratio that was actually displayed.
To get the real speedup ratio that you can reach, you have to find every problem, not just a few.
That link shows how to do it.