Head scratching
In one Optimization article I wrote, I showed how the use of a function pointer to call objc_msgSend can speed up method calling by up to 10%. Now with my new article, where I show how this can be done about 20% faster, I wanted to contrast this against the original speed and the gain received from the function pointers.
operateAnnihilate uses plain [object method] calls. Fast operateAnnihilateFast is the one using function pointers. operateAnnihilateFastest is the new stuff :) The results were:
Starting operateAnnhilate... Stopped operateAnnhilate 8891ms elapsed_ Starting operateAnnihilateFast... Stopped operateAnnihilateFast 9717ms elapsed_ Starting operateAnnihilateFastest... Stopped operateAnnihilateFastest 6456ms elapsed_
Oops! Plain message sending is faster now. This has me stumped.
So I went over it with otool. To my pleasant surprise I noticed that with XCode 1.5 and the newest gcc installed, the dummy methods are indeed compiled to blr and blr only. Most optimal :). The function pointer call sequence itself, though is still quite lacking as one stall could easily be avoided.
At first I thought that maybe Apple took the suggestion and used
function pointers itself, somehow more optimally... They
don't.
Then I figured they might have implemented some of the Tiger
techniques already... They haven't.
Then I traced through both codes with the debugger. Still the
function pointer technique is about six instructions shorter...
Smells like a cache problem...