JDK-7122740 : PropertyDescriptor Performance Slow
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-12-19
  • Updated: 2013-11-05
  • Resolved: 2012-07-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u6Fixed 8 b23Fixed
Related Reports
Duplicate :  
Relates :  
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.
18-07-2012

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<>();
16-01-2012

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.
16-01-2012