[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CF Performance vs. Foundation (Re: Worth it for an object to cache its own IMPs?)
On 02/03/2004, at 6:46 AM, Scott Stevenson wrote:
>
> On Mar 1, 2004, at 2:18 AM, Izidor Jerebic wrote:
>
>> What do you mean by parsing? Reading from a file and building a tree
>> structure or walking the structure already built? Extracting parts of
>> files or reading complete files as trees of objects for later
>> perusal?
>
> Basically, I have hierarchy of arrays and dictionaries that are all
> loaded into memory at startup. As the program runs, I need to get at
> various parts of the structures very frequently. Right now, it's just
> too slow.
I've found that the CF objects can be more flexible than their NS
equivalents. For example, instead of doing key1 -> object, key2 ->
object in NSDictionary, you can just do two different kinds of CFSet
with different callbacks -> should be faster, easier to do
cross-lookups and less objects in memory. The other advantage is that
the key object doesn't really need to be an object in a CFDictionary,
so you might get some optimization that way if the equal: and/or hash:
calls are too prevalent or inefficient.
One thing I learnt from STL experience is often a dictionary is more
inefficient than a set, especially if the value object needs to know
its key.
The other thing to think about is whether you can flatten your
hierarchy somewhat. Instead of key1 -> (key2 -> object), try something
like (key1, key2) -> object. The multiple objects for a single key
collections will help e.g. bags.
[preaching mode on]
You said you're at the optimization stage and would prefer not to
change your data structures. But often it is changing the algorithm
that will deliver the significantly faster result, rather than tweaking
the low-level details. Premature optimization may be root of all evil,
but sometimes the optimization required is a change of data structure
and/or algorithm. Consider yourself at a local maximum in your graph,
you still have to search for the global maximum rather than get stuck
in the same spot.
[preaching mode off]
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com