Key-Value Observing speed
Key-Value Observing speed
- Subject: Key-Value Observing speed
- From: Gwynne Raskind <email@hidden>
- Date: Fri, 12 Mar 2010 12:35:01 -0500
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden