[Mono-dev] Hashtable.Clone speedup.

Miguel de Icaza miguel at ximian.com
Thu May 22 20:01:14 EDT 2008


Hello folks,

    The following patch doubles the speed of the Hashtable.Clone()
method by copying the data directly, instead of using an enumerator and
repopulating the hashtable.

    Additionally, since the way that Clone() works today is by passing a
capacity value based on the actual number of slots on the Hashtable and
the Hashtable constructor likes to make its own guesstimates as to the
capacity of the table based on the loadFactor, it might end up resizing
the hashtable more than once.

    What to look for: I avoided copying two fields hashKeys and
hashValues as those seem like caches that are computed on demand.   But
did I miss anything important?

    You can reproduce locally using the attached program, invoke like
this:

	mono clone N M

    Where N is the number of slots to stick in the Hashtable, and M is
the number of copies to perform.

Miguel.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable.patch
Type: text/x-patch
Size: 2268 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080522/f6cd1790/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clone.cs
Type: text/x-csharp
Size: 602 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080522/f6cd1790/attachment-0001.bin 


More information about the Mono-devel-list mailing list