string hash performance

Jeff Sturm jsturm@one-point.com
Wed Aug 7 18:32:00 GMT 2002


On Wed, 7 Aug 2002, Eric Blake wrote:
> Classpath's implementation also caches the hashcode. You can also
> verify, by reflection, that Sun's version of the JDK likewise does
> caching.

Interesting. I also noticed in hprof output that Object instances are 4
bytes while Strings are 20 bytes.
> Thus, if gcj does merge with
> classpath, all String objects would become at least 4 bytes larger to
> store the cache.

It's hard to say if String is better off with or without. At least
cachedHashCode need not be volatile or synchronized since any
loads/stores should be atomic.
My interpreter needs some large string tables. I'll see about
benchmarking it with cachedHashCode.
Jeff


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /