On Mar 12, 2010, at 9:35 AM, Gwynne Raskind wrote: > While profiling a project I'm working on, I found that while most of my time > was being spent in glFlush() (which is completely expected for an > OpenGL-based game), a non-trivial amount of time is being spent in dozens of > KVO internal methods and functions. Most especially, I noticed that KVO (or > possibly the KVC beneath it) makes heavy use of NSInvocation-based > forwarding, which is known to be the slowest possible code path for message > dispatch. > > KVO is central to my code's structure; I rely on it for everything to know > what everything else is doing without sprinkling manual notifications all > over the code. Is there any way to trick the runtime into taking some faster > code paths? It's really troublesome to see property setter methods taking up > almost as much total time as the audio converter thread in Instruments. Would > it help if my properties were sets of integers instead of structures > (specifically, NSPoint and NSRect are used quite a bit)? Would it be just > blindly insane to think that a NSRectObject would be faster somehow than a > plain NSRect because of the structure return trickery the runtime has to do? > > And if there's nothing I can do with Apple's KVO, is it even remotely > realistic to consider writing my own quickie version of KVO that takes faster > paths since I can tweak it for my uses? > > (Side note, Michael Ash's MAKVONotificationCenter has been a panacea for all > manner of minor issues I've had with the KVO implementation, kudos Mike!) > > Please, no one say I shouldn't be writing a game with Objective-C; KVO is the > only thing that's tripped me up speed-wise about it. (Well, that and the > audio threads doing a heck of a lot of sound processing, I keep wondering if > I can put my WAV files into some format that requires less CA conversion or > whether it's NSSound forcing that on me...) > > -- Gwynne
I think KVO only uses NSInvocation when setting or getting non-standard aggregate types. So if your property is any primitive C type, any ObjC object, or an NSPoint, NSRect, NSRange, or NSSize, then it will not use NSInvocation. If it's a custom struct it will. Does that seem plausible based on what your property types are? If not, it would be helpful to post a backtrace for the call to +[NSInvocation invocationWithMethodSignature:], so we can figure out what's happening. -Peter _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com