db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John M <iniq...@yahoo.com>
Subject [PATCH] performance on PersistenceBrokerImpl, SqlHelper, ClassDescriptor
Date Fri, 27 Jun 2003 21:07:10 GMT
I have done some analysis with Sun's JFluid while
trying to optimize parts of my application which needs
to load a lot of data at once for processing.  I'm
using rc4 from cvs with just the PB interface. 
Anyway, I have discovered a couple of places where a
quick fix offered some substantial performance gains.

First, I noticed that in
ClassDescriptorgetDynamicProxyClass() the proxy class
interface list was being created each time.  As far as
I know this stuff is static, so I cached the list as a
member variable.  The patch is large below but is
really just wrapping the existing code in an if like
the other methods that cache something.

Second, in PersistenceBrokerImpl.getReferencedObject,
I added a check for the object in the cache.  I had a
situation where the object was already in the cache,
but instead of loading the object directly a proxy was
created which later resolved to the cached object,
which wasted quite a bit of time.

Lastly, I reordered the switch on column type in
SqlHelper, putting common field types like INTEGER and
VARCHAR first and less common types at the end.  I
didn't measure this change but it seems that bouncing
through as few case checks as possible would be best. 
I didn't attach the patch for this, but I can make it
available if desired.

I inlined the patches; let me know if I should repost.
These changes work fine for me but OJB is way too
large for me to know about everything that is going
on, and I don't use many of the features, so let me
know if there are consequences to the changes
suggested.

John Marshall
Connectria

****************************************
cvs diff -u PersistenceBrokerImpl.java 
Index: PersistenceBrokerImpl.java
===================================================================
RCS file:
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
retrieving revision 1.17
diff -u -r1.17 PersistenceBrokerImpl.java
--- PersistenceBrokerImpl.java	25 Jun 2003 20:30:58
-0000	1.17
+++ PersistenceBrokerImpl.java	27 Jun 2003 21:03:56
-0000
@@ -1263,6 +1263,12 @@
         // ensure that top-level extents are used for
Identities
         referencedClass =
descriptorRepository.getTopLevelClass(rds.getItemClass());
 
+        //jmm why not see if the object has already
been loaded
+        Identity id = new
Identity(rds.getItemClass(), referencedClass, pkVals);
+        Object temp = objectCache.lookup(id);
+        if ( temp != null ) return temp;
+        //end jmm
+
         if (rds.isLazy())
         {
             /*
*********************************************
cvs diff -u ClassDescriptor.java 
Index: ClassDescriptor.java
===================================================================
RCS file:
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
retrieving revision 1.62
diff -u -r1.62 ClassDescriptor.java
--- ClassDescriptor.java	13 May 2003 15:23:29 -0000
1.62
+++ ClassDescriptor.java	27 Jun 2003 20:54:50 -0000
@@ -987,6 +987,13 @@
 		return getLockingFields().length > 0;
 	}
 
+
+//jmm
+    /**
+     * Cache information about the interfaces need
for dynamic proxy.
+     */
+    private Class[] m_dynamicProxyClassInterfaces;
+    
 	/**
 	 * returns a dynamic Proxy that implements all
interfaces of the
 	 * class described by this ClassDescriptor.
@@ -995,48 +1002,54 @@
 	 */
 	public Class getDynamicProxyClass()
 	{
-		Class clazz = getClassOfObject();
-		Class superClazz = clazz;
-		Class[] interfaces = clazz.getInterfaces();
-
-		// clazz can be an interface itself and when
getInterfaces()
-		// is called on an interface it returns only the
extending
-		// interfaces, not the interface itself.
-		if (clazz.isInterface())
-		{
-			Class[] tempInterfaces = new
Class[interfaces.length + 1];
-			tempInterfaces[0] = clazz;
-
-			System.arraycopy(interfaces, 0, tempInterfaces, 1,
interfaces.length);
-			interfaces = tempInterfaces;
-		}
-
-		// add all interfaces implemented by superclasses
to the interfaces array
-		while ((superClazz = superClazz.getSuperclass()) !=
null)
-		{
-			Class[] superInterfaces =
superClazz.getInterfaces();
-			Class[] combInterfaces = new
Class[interfaces.length + superInterfaces.length];
-			System.arraycopy(interfaces, 0, combInterfaces, 0,
interfaces.length);
-			System.arraycopy(superInterfaces, 0,
combInterfaces, interfaces.length,
superInterfaces.length);
-			interfaces = combInterfaces;
-		}
+        Class clazz = getClassOfObject();
 
-		/**
-		 * Must remove duplicate interfaces before calling
Proxy.getProxyClass().
-		 * Duplicates can occur if a subclass re-declares
that it implements
-		 * the same interface as one of its ancestor
classes.
-		 **/
-		HashMap unique = new HashMap();
-		for (int i = 0; i < interfaces.length; i++)
-		{
-			unique.put(interfaces[i].getName(),
interfaces[i]);
-		}
-		interfaces = (Class[]) unique.values().toArray(new
Class[unique.size()]);
+        if ( m_dynamicProxyClassInterfaces == null )
{
+    		Class superClazz = clazz;
+    		Class[] interfaces = clazz.getInterfaces();
+    
+    		// clazz can be an interface itself and when
getInterfaces()
+    		// is called on an interface it returns only
the extending
+    		// interfaces, not the interface itself.
+    		if (clazz.isInterface())
+    		{
+    			Class[] tempInterfaces = new
Class[interfaces.length + 1];
+    			tempInterfaces[0] = clazz;
+    
+    			System.arraycopy(interfaces, 0,
tempInterfaces, 1, interfaces.length);
+    			interfaces = tempInterfaces;
+    		}
+    
+    		// add all interfaces implemented by
superclasses to the interfaces array
+    		while ((superClazz =
superClazz.getSuperclass()) != null)
+    		{
+    			Class[] superInterfaces =
superClazz.getInterfaces();
+    			Class[] combInterfaces = new
Class[interfaces.length + superInterfaces.length];
+    			System.arraycopy(interfaces, 0,
combInterfaces, 0, interfaces.length);
+    			System.arraycopy(superInterfaces, 0,
combInterfaces, interfaces.length,
superInterfaces.length);
+    			interfaces = combInterfaces;
+    		}
+    
+    		/**
+    		 * Must remove duplicate interfaces before
calling Proxy.getProxyClass().
+    		 * Duplicates can occur if a subclass
re-declares that it implements
+    		 * the same interface as one of its ancestor
classes.
+    		 **/
+    		HashMap unique = new HashMap();
+    		for (int i = 0; i < interfaces.length; i++)
+    		{
+    			unique.put(interfaces[i].getName(),
interfaces[i]);
+    		}
+    		interfaces = (Class[])
unique.values().toArray(new Class[unique.size()]);
+            
+            m_dynamicProxyClassInterfaces =
interfaces;
+        }
 		// return dynymic Proxy Class implementing all
interfaces
-		Class proxyClazz =
Proxy.getProxyClass(clazz.getClassLoader(),
interfaces);
+		Class proxyClazz =
Proxy.getProxyClass(clazz.getClassLoader(),
m_dynamicProxyClassInterfaces);
 
 		return proxyClazz;
 	}
+//end jmm
 
 	/**
 	 * return all AttributeDescriptors for the path<br>


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

Mime
View raw message