Re: Key-Value Observing speed
Re: Key-Value Observing speed
- Subject: Re: Key-Value Observing speed
- From: Mike Abdullah <email@hidden>
- Date: Fri, 12 Mar 2010 23:21:30 +0000
On 12 Mar 2010, at 22:41, Gwynne Raskind wrote:
> On Mar 12, 2010, at 4:52 PM, Peter Ammon 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.
>> 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.
>
>
> You're right; the specific call that's causing the worst speed issues is returning a property typed with this structure:
>
> typedef struct { int32_t x, y; } IntegerPoint;
>
> It's not necessarily feasible to switch this to an NSPoint; it means digging up every point in the code that relies on signed 32-bit integer math and doing manual typecasting (or calling lround()) away from CGFloat. If there's no way to cheat KVO into doing this sanely, I'll resign myself to it, but I kinda hope there's something a little less annoying.
>
> (It's even more annoying because it *was* an NSPoint in a much earlier iteration of the code and I changed it because it simplified the code in two dozen places, and because the property in question is integer and doesn't need the slower floating-point instructions to manipulate it.)
What options are you using to observe this property? What if you have an additional method you bind to that returns an IntegerPoint already wrapped up in an NSValue or similar?
_______________________________________________
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