Perhaps the most important thing that I learned during my tenure in Professor Ronald Kluger’s laboratory was this: “When you have an unusual observation, one of two things has happened: you’ve either made a discovery or a mistake. Mistakes are much more common than discoveries.” Ron inherited this saying from his Ph.D. supervisor, Professor Frank Westheimer.
Last week, I spent quite a bit of time investigating the performance penalty that one pays for invoking a virtual method via an interface reference as opposed to using an object reference. Since I did this work on my laptop, I initially looked at the performance penalty on a Pentium III-M processor. Later, I looked at the performance penalty on an Athlon 1200 processor. More recently, I looked at the performance penalty on a Pentium 4 processor.
Along the way, I had a number of unusual observations. At the time, I didn’t have a framework for systematically ruling out alternate explanations for those observations, so I reported the results that I had. As it turns out, I was lucky to get more-or-less correct results (they weren’t exactly correct due to a calculation error, but they were in the right ballpark). The rest of this entry goes on to explain what happened. I began by investigating what I thought was a very simple model system, and at the end wound up learning quite a lot about IA32 architecture and performance.
NOTES:
PII and PIII processors aggressively prefetch instructions in 16-byte aligned boundaries. You will pay a significant performance penalty if the target of a branch results in two 16-byte fetches (i.e. the instruction overlaps this boundary).
Question: What happens on P4 and AMD processors?