Re: Key-Value Observing speed
Re: Key-Value Observing speed
- Subject: Re: Key-Value Observing speed
- From: Quincey Morris <email@hidden>
- Date: Fri, 12 Mar 2010 16:22:07 -0800
On Mar 12, 2010, at 14:41, Gwynne Raskind wrote:
> 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.)
If "not necessarily feasible" just means changing code in a number of places, I think you should reconsider. When the alternative is baking in a mediocre design compromise, you'll have to live with the consequences forever more.
In practice, I'd suggest one of two things (which actually amount to just about the same thing in the end):
1. Make 2 integer properties for the x and y components separately. You can keep the struct property as a kind of "convenience" property, which means that much of code won't need to be changed. The issue is not that you don't want the struct property, the issue is that you don't want to *observe* the struct property. So, observe the x property or the y property or both instead.
2. Or, add a derived property (which can be transient) whose value is unimportant, but which triggers a KVO notification when the struct property changes. Observe the derived property instead of the struct property.
Neither of those approaches requires you to retool *all* your already-written code, just the part that adds and removes observers. #2 won't help if you need to bind to the struct property (and KVO notifications via the binding are part of your performance problem), but #1 should work for that.
_______________________________________________
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