JDK-5002893 : Perf. deterioration in 1.4.2 when many charset switches
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.2_03
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: generic
  • Submitted: 2004-02-25
  • Updated: 2004-04-26
  • Resolved: 2004-04-26
Related Reports
Duplicate :  
Description
We found the performance deterioration occurs in 1.4.2 comparing with
that in 1.3.1.


REPRODUCE:
 
  (1) Compile the attached program 
  (2) Launch "java CharsetTest01" in 1.3.1 and 1.4.2


RESULT :
 
  We can see  different performance in the lists which the
  test program outputs.

  In 1.3.1_11,

K:\perf-char-set>java -version
java version "1.3.1_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_11-b02)
Java HotSpot(TM) Client VM (build 1.3.1_11-b02, mixed mode)

K:\perf-char-set>java CharsetTest01
Start
Finished: 651ms


However, in 1.4.2_03,


K:\perf-char-set>java -version
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

K:\perf-char-set>java CharsetTest01
Start
Finished: 23724ms


This seems to worse than 1.3.1.
We believe the 23.7[sec] in 1.4.2 is too slow than 0.7[sec] in 1.3.1 !!



CONFIGURATION :
  - OS : WindowsXP( SP1, Japanese )
  - MPU : Pentium IV 1.4[GHz]
  - Mem : 384[MB]
  - JRE : 1.4.2_03



NOTE:

In 1.5,

K:\perf-char-set>java -version
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b38)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b38, mixed mode)

K:\shares2\fujitsu\perf-char-set>java CharsetTest01
Start
Finished: 6259ms


The perf. in 1.5 , 6.3[sec] seems to be better than 23[sec] in 1.4.2, 
but still too slower than 0.6[sec] in 1.3.1.
 

============================================================================

Comments
SUGGESTED FIX === Provided suggested fix ==== *** Charset.java 2004-02-06 09:45:24.000000000 +0900 --- Charset.java.org 2003-05-01 08:04:01.000000000 +0900 *************** *** 371,404 **** } } - private static volatile java.util.HashMap cshash = new java.util.HashMap() ; - private static Charset lookup(String charsetName) { if (charsetName == null) throw new IllegalArgumentException("Null charset name"); ! ! String key = charsetName.intern(); ! if(cshash.containsKey(key)) { ! Object value = cshash.get(key); ! if(value != null) ! return (Charset)value; ! else ! return null; ! } ! Charset cs = standardProvider.charsetForName(charsetName); ! if (cs != null) { ! cshash.put(key, cs); ! return cs; ! } cs = lookupViaProviders(charsetName); ! if (cs != null) { ! cshash.put(key, cs); ! return cs; ! } ! ! cshash.put(key, null); // negative cache ! return null; } /** --- 371,391 ---- } } private static Charset lookup(String charsetName) { if (charsetName == null) throw new IllegalArgumentException("Null charset name"); ! Object[] ca = cache; ! if ((ca != null) && ca[0].equals(charsetName)) ! return (Charset)ca[1]; Charset cs = standardProvider.charsetForName(charsetName); ! if (cs != null) ! return cache(charsetName, cs); cs = lookupViaProviders(charsetName); ! if (cs != null) ! return cache(charsetName, cs); ! /* Only need to check the name if we didn't find a charset for it */ ! checkName(charsetName); ! return null; } /** ###@###.### 2004-02-25 ===========================================================================
25-02-2004

EVALUATION This is essentially the same problem as described in 5002890. Closing as a duplicate. -- ###@###.### 2004/4/25
04-12-0191