Re: cocoa-dev digest, Vol 2 #4140 - 15 msgs
Re: cocoa-dev digest, Vol 2 #4140 - 15 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #4140 - 15 msgs
- From: Glen Low <email@hidden>
- Date: Sat, 8 May 2004 01:14:06 +0800
Nicko:
Reading and writing the instance variable many times using direct
access records 6.8ns per loop on a 1.25GHz G4 whereas using methods to
get and set the same instance variable takes 91ns per loop, thirteen
times slower. There is clearly a large cost associated with making the
method calls themselves, and worse the disruption of processor flow by
having to make calls to objc_msgSend all the time means that the
compiler's optimisation phase is much less effective; in this test I
deliberately forced the compiler not to optimise around these calls and
removing the 'volatile' directive drops the direct access loop to
1.8ns, 50 time faster than method access. In many cases where dealing
with large bodies of data the overhead of using method access to
instance variables is unacceptable.
Yes it is somewhat shocking that method calls are bottlenecked through
objc_msgSend, which itself is in a dylib and has to be dispatched
through a Mach-O stub. I wonder if Apple decides to ship a static lib
version of objc_msgSend that could be linked into your own code, would
we suddenly see our Cocoa apps speeding up...
On the other hand, for slightly better speed while preserving
encapsulation, you can always fetch the IMP pointer and dispatch
through that. That should remove at least 2 of the hoops the CPU has to
jump through to get to your method code.
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.