> >        For performance, there's one exception: binary serialization of a
> > Dictionary<T, U>. This is tremendously slow compared to a Hashtable. For
> > serialization purposes use something like this:
>
> [FastDictionary]
>
> Have you got any data on the speedup? When I look at Dictionary in
> Reflector, it doesn't seem to be that much different from your code:
> they just
> (1) serialize the KeyValuePairs instead of serializing keys and values
> as separate object arrays, and
> (2) they initialize the buckets before inserting the deserialized
> KeyValuePairs (probably to preserve the ordering of the dictionary,
> although I haven't checked this).
>
> So, I'm wondering how much more efficient your FastDictionary would
> be, especially since you say Dictionary serialization is tremendously
> slow. Is serializing a generic type array in (1) so much slower than
> serializing two object arrays?
>
> (Also, it seems your code does not preserve the order of items in the
> dictionary and it doesn't serialize the comparer, if any. Won't matter
> most of the time, but worth knowing.)

        The class I posted was sufficient for our purposes, so if you need
extra features you need do to some tweaking.

        Some time ago, we did some research about speeding up binary
serialization for remoting and we found out that the .NET 1.x codebase was
faster than the .NET 2.0 codebase. After profiling the code, it turned out
that the generic dictionary objects were slowing things down. Replacing them
with hashtables made it equal again (or .net 2.0 became slightly faster).
Looking deeper into it, the GetObjectData routines differ. When I made a
Dictionary class which had a similar GetObjectData routine as Hashtable,
namely serializing the keys and values as object arrays, it was solved.

        It's not that a generic class is always slower, but it's not hurting
to look into ways to speed things up when they can be sped up ;). Try it, you
will see a big difference. I don't have numbers to back it up, the class was
made more  than a year ago, but that it was significant is a fact.

        The Order of the items isn't important for hashtables/dictionaries, as
the order isn't defined: you can't pull the data out in a given order.

                FB



===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to