United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7122740 PropertyDescriptor Performance Slow
7122740 : PropertyDescriptor Performance Slow

Details
Type:
Bug
Submit Date:
2011-12-19
Status:
Resolved
Updated Date:
2012-07-30
Project Name:
JDK
Resolved Date:
2012-07-30
Component:
client-libs
OS:
windows_7
Sub-Component:
java.beans
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
8

Related Reports
Backport:
Duplicate:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
Java 7u2

A DESCRIPTION OF THE PROBLEM :
Bad performance when a bean method from the PropertyDescriptor is invoked.

see https://forums.oracle.com/forums/thread.jspa?forumID=933&threadID=2322123

REGRESSION.  Last worked in version 6u29

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the provided test case - with Java 6 it takes around 100ms with Java 7 around 5000ms.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Execution time around 100ms
ACTUAL -
Execution time around 5000ms

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.beans.PropertyDescriptor;

import javax.swing.JComponent;
import javax.swing.JPanel;

public class PropertyDescriptorTest
{
  public static void main(String[] args)
  {
    JComponent c = new JPanel();
    String name = "name";
    long start = System.currentTimeMillis();
    try
    {
      for (int i=0; i<1000; i++)
        new PropertyDescriptor(name, c.getClass()).getReadMethod().invoke(c);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    long stop = System.currentTimeMillis();
    System.err.println(stop-start);
  }
}
---------- END SOURCE ----------

                                    

Comments
EVALUATION

Seems, I found a way to improve performance more.
                                     
2012-07-18
EVALUATION

The TypeResolver class used to process generic types spent time in the constructor.
New cache based on the WeakCache class will increase performance more than 10 times.
                                     
2012-01-16
SUGGESTED FIX

public static Type resolve(Type actual, Type formal) {
-        return new TypeResolver(actual).resolve(formal);
+        return getTypeResolver(actual).resolve(formal);
     }
 
     public static Type[] resolve(Type actual, Type[] formals) {
-        return new TypeResolver(actual).resolve(formals);
+        return getTypeResolver(actual).resolve(formals);
     }
 
+    public static TypeResolver getTypeResolver(Type type) {
+        synchronized (CACHE) {
+            TypeResolver resolver = CACHE.get(type);
+            if (resolver == null) {
+                resolver = new TypeResolver(type);
+                CACHE.put(type, resolver);
+            }
+            return resolver;
+        }
+    }
+
+    private static final WeakCache<Type, TypeResolver> CACHE = new WeakCache<>();
                                     
2012-01-16



Hardware and Software, Engineered to Work Together