United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7057459 Regression: Performance degradation with java.beans.XMLEncoder
JDK-7057459 : Regression: Performance degradation with java.beans.XMLEncoder

Details
Type:
Bug
Submit Date:
2011-06-21
Status:
Resolved
Updated Date:
2011-08-18
Project Name:
JDK
Resolved Date:
2011-08-18
Component:
client-libs
OS:
generic,windows_xp
Sub-Component:
java.beans
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u2 (b03)

Related Reports
Backport:
Duplicate:
Relates:

Sub Tasks

Description
SYNOPSIS
---------
Performance degradation with java.beans.XMLEncoder

OPERATING SYSTEM
----------------
All

FULL JDK VERSION
----------------
JDK 7 (tested with b146)
Performance first regressed in either JDK 7 b65 or JDK 7 b66.
Degradation became worse in b71 or b72.
For JDK 6, became slightly worse in 6u25.  Not reproducible in 6u24.

REPRODUCTION INSTRUCTIONS
-------------------------
1. Compile the two attached Java classes.
2. Run "java JavaBeanXmlEncoder"

Comparison of results from 7b64, 7b66, and 7b72:

---- 7b64 ----
Encoding to a file .....
Total Time taken for Encoding as XML =   1032   in Millsecond
-------------

---- 7b66 ----
Encoding to a file .....
Total Time taken for Encoding as XML =   6141   in Millsecond
-------------

---- 7b72 ----
Encoding to a file .....
Total Time taken for Encoding as XML =   7954   in Millsecond
-------------

TESTCASE
--------
See attachments.

                                    

Comments
SUGGESTED FIX

src/share/classes/java/beans/Encoder.java

     public PersistenceDelegate getPersistenceDelegate(Class<?> type) {
         PersistenceDelegate pd = this.finder.find(type);
-        return (pd != null) ? pd : MetaData.getPersistenceDelegate(type);
+        if (pd == null) {
+            pd = MetaData.getPersistenceDelegate(type);
+            if (pd != null) {
+                this.finder.register(type, pd);
+            }
+        }
+        return pd;
     }
                                     
2011-06-22
EVALUATION

The root of cause is the 6380849 RFE: Automatic discovery of PersistanceDelegates.
We added this ability similar to discovery of PropertyEditors and BeanInfos.  It looks up for persistance delegates in the following order:
- 1. custom delegate registered in the cache
- 2. custom delegate via Reflection and register it in the cache (new behaviour)
- 3. shared default delegate in the Metadata class
Note that the most applications use default delegates.  So we search for custom delegate via Reflection for almost all objects.  It significantly reduces the performance.  I suggest to modify the third step: we should register shared default delegate in the cache.  It slightly increases a memory usage, but solves the problem with the performance.  See Suggested Fix.
                                     
2011-06-22



Hardware and Software, Engineered to Work Together