harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Salikh Zakirov <Salikh.Zaki...@Intel.com>
Subject Re: [drlvm] string interning in java
Date Fri, 28 Jul 2006 21:54:25 GMT
Alex Blewitt wrote:
> There's a heck of a lot wrong with intern()

I agree with all of your points. Indeed, it makes little sense
doing  a == b.intern() instead of a.equals(b).

My original observation was that interning makes perfect sense
for localized log messages, because the code like

    println(MessageBundle.get("how are you?"));

is going to be translated to using LDC bytecode instruction,
which is in turn compiled into calling LDC runtime helper,
which interns string on the first call and caches it for
later invocations, so that for all subsequent executions 
of this code will get interned string pointer very cheaply.
(it works this way in DRLVM)

So, I think the design of this particular part of Java system
is very clever.

Now, back to business. The pure java implementation I have tried
somewhat slows down the execution. Preallocation the hash array
large enough to avoid rehash() helps, but still it is slower
than the native code. I have measured the time to run Hello application on my laptop
(abount 300 total interned strings)

native intern:	avg    0.267 +/- 0.001 =    26.980 / 101, min    0.257, max    0.347
java intern:	avg    0.270 +/- 0.001 =    27.285 / 101, min    0.261, max    0.345

which is slowdown of about 1.5%.

I will try to write a custom code instead of using WeakHashMap to reduce hash calculation.

Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

View raw message