speed, Foundation vs. Core Foundation

Member
Posts: 208
Joined: 2005.04
Post: #1
I recently wrote a HUGE objective-C class which makes extensive use of NSDictionary and NSArray (as well as their mutable counterparts). Some of the methods are quite long. I'm quite happy with how quickly the codes runs, but I'm wondering if I could push it to execute even faster.

How much performance gain do you think I'll see if I were to switch from using NS* to CF* inside my larger methods? Since the Foundation classes are implemented in C (due to the whole toll-free bridge thing), I'm guess the only thing I'd be saving would be the time extra time it takes to invoke an objective-C method (as opposed to calling a C function).

Given that some of my larger methods make many hundreds of calls to Foundation storage objects, I figure it might be worth the trouble to convert from a Foundation based implementation to a Core Foundation based one.

Thoughts? Experiences?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
The pain of those CF function names isn't worth it if it's running fast enough already Smile
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #3
ya, CF is kind of awkward... my code already contains quite a bit of CF in it because it deals with HID Manager, so I've gotten used to API. I initially found it quite frustrating that many of the function calls take many more parameter than their objective-C cousins.

I guess I'm just looking for a ballpark figure... 10%? 20%?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Shark it and find out how much time you're wasting in ObjC method dispatch overhead. There's no substitute for profiling.
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #5
OneSadCookie Wrote:Shark it and find out how much time you're wasting in ObjC method dispatch overhead. There's no substitute for profiling.

Done and done Smile
Shark shows that this
-[NSDictionary(NSKeyValueCoding) valueForKey:]
only takes up 0.2% of the total CPU time, and that's the most CPU hungry Foundation call it lists!

So, as always (Rasp), you're right Keith... it would be a total waste of time to convert the code to CF
Quote this message in a reply
Oldtimer
Posts: 832
Joined: 2002.09
Post: #6
When this discussion comes up, I always relate the best story I ever experienced on this matter. I was asked to port a physics-intensive FPS engine to the Mac, which ran more than 20 times slower than on a PC with about the same specs. So, FPS engine... physics intensive... what could slow that down? 3D rendering, of course. Physics calculations. Skeletal animation?

Well, no. It was a really really stupid function that compared two strings. Once I substituted that slow and overkilling function, the Mac version ran at 1.5 times the speed of the PC version. Shark is your friend, always.
Quote this message in a reply
Post Reply