-
Enhancement
-
Resolution: Fixed
-
P4
-
1.4.0
-
tiger
-
x86
-
windows_nt
Name: nt126004 Date: 11/14/2002
FULL PRODUCT VERSION :
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
and
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
FULL OPERATING SYSTEM VERSION :
All
A DESCRIPTION OF THE PROBLEM :
The current dynamic proxy cache key implementation is
inefficient in performance and memory.
The current implementation creates a string concatenation
(using a StringBuffer) of all of interface names as the
cache key. Here is the explanation from the Proxy.java
source:
/*
* Using a string representation of the proxy interfaces as keys
* in the proxy class cache instead of a collection of their Class
* objects is sufficiently correct because we require the proxy
* interfaces to be resolvable by name through the supplied class
* loader, and it has a couple of advantages: matching String
* objects is simpler and faster than matching collections of
* objects, and using a string representation of a class makes
* for an implicit weak reference to the class.
*/
Though a collection of the Class objects may not be
appropriate (due to the Strong references), a collection of
the Class names performs better than the StringBuffer
implementation.
The following example implementation performs 20% faster
(including key creation, hashCode() and equals()) than the
current in my tests, uses significantly less memory,
creates less objects, and still upholds the implicit weak
reference requirement:
private Object createKey(Class[] interfaces) {
String[] names = new String[interfaces.length];
for (int i = 0; i < interfaces.length; i++)
names[i] = interfaces[i].getName();
return java.util.Arrays.asList(names);
}
REPRODUCIBILITY :
This bug can be reproduced always.
(Review ID: 165522)
======================================================================