[Mono-dev] String.GetHashCode()
Robert Jordan
robertj at gmx.net
Sat Dec 1 12:29:50 EST 2007
Hi Alan,
Alan McGovern wrote:
> Also, just looking at the string source a bit more closely, it has a
> GetCaseInsensitiveHashcode method too, so i'd assume that would need to be
> cached too which would mean 8 bytes would be needed. This wouldn't scale
> well.
>
> Fair enough. Twas just an idea.
nah, don't give up too early! :) If the string is longer than "n",
you could allocate 4 or even 8 additional bytes at the end of the
array for lazily computed hash codes.
Open questions:
- What's the optimal "n" for all common application classes
mono is used for? :) It looks like it should be dynamically
computed & adjusted based on profiling data collected at
runtime.
- What's the real gain of this optimization? If "n" tends to
be really large (say 1-4KB), what's the probability of
such large strings being used as a hash key?
This question can be reduced to "how frequently is
s.GetHashCode called, where s.Length > n".
In mono's class libs sources there is only one place (I know
of) where large strings are potentially hashed: Sys.Web's
cache management.
Robert
More information about the Mono-devel-list
mailing list