string hash performance
Jeff Sturm
jsturm@one-point.com
Wed Aug 7 17:51:00 GMT 2002
On Wed, 7 Aug 2002, Boehm, Hans wrote:
> Is it surprising that the IBM JDK would cache the hashCode?
Perhaps not. However if it were cached I'd expect it to be about as fast
as String.length(). My first tests revealed something like 16us for length()
vs. 34us for hashCode(). So I figured it might be doing a little more
than just returning an instance field.
> If Object.hashCode() computes hash values based on address, and the
> garbage collector compacts, then you need to have someplace to store
> previously computed hashCodes when an object is moved. (That could be
> in an external address-indexed table, I guess.) It seems at least
> possible that String.hashCode could use the same space.
Good point. I found however that System.identityHashCode() returns a
different value altogether, so it appears likely that the string hash
occupies extra space.
Jeff
More information about the Java
mailing list