[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Worth it for an object to caching its own IMPs?



Scott,

This has been said before, but I'd like to add another voice to the 
fray: do not optimize without measuring first. You said first you 
wanted to optimize because:

> I'm in a situation where an object is calling methods on itself 
> frequently and latency is important.

But you said in a followup email:

> The code in question involves a lot of plist/dictionary/array parsing 
> and such.

 From this I can assure you that ObjectiveC message passing is not 
likely to be your most important performance hit. The Objective-C 
runtime is already caching most of the cacheable information anyway. If 
you touch the disk even just once to read a file message passing is 
going to be in the order of the insignificant...

Write your code, make it work well, and if it is too slow then, and 
only then, measure the performance.  Do use Sampler. Optimize the place 
were you spend the most time. The only case where I can remember IMP 
caching yielding a nice performance boost was in the implementation of 
KeyValueCoding when it was used only by EOF, not a piece of code you 
should be writing everyday. And even in this case the caching of IMP 
only played a small part in the gain, it was far more productive to 
cache the result of what to invoke or modify.

> Is it a reasonable strategy to switch over to c functions that use CF 
> types? In other words, is there going to be much of a difference if 
> I'm still using CF objects inside the function

There is not much differences today between calling a CF vs a NS 
method/function. CF and NS objects do share their implementation, and 
again, the gain you are going to have by avoiding an objc_msg send is 
going to be minimal.

Cheers,
-- Eric
PS: Any good reason why I can't send a signed message to this list? I 
got a "The message's content type was not explicitly allowed" from the 
mail server at omnigroup...