You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2014/12/01 08:58:28 UTC

cayenne git commit: documenting performance hotspots

Repository: cayenne
Updated Branches:
  refs/heads/master 464c548c4 -> 2c06db649


documenting performance hotspots


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/2c06db64
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/2c06db64
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/2c06db64

Branch: refs/heads/master
Commit: 2c06db649f7a4a19c463c33cf7ac2f42ff92eb87
Parents: 464c548
Author: aadamchik <aa...@apache.org>
Authored: Mon Dec 1 10:14:02 2014 +0300
Committer: aadamchik <aa...@apache.org>
Committed: Mon Dec 1 10:18:34 2014 +0300

----------------------------------------------------------------------
 .../org/apache/cayenne/access/DbLoader.java     | 13 +++++---
 .../apache/cayenne/util/EntityMergeSupport.java | 33 ++++++++++++--------
 2 files changed, 28 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/2c06db64/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java b/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
index 3a103e1..8e37da1 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
@@ -466,11 +466,14 @@ public class DbLoader {
         for (DbEntity dbEntity : entities) {
 
             // check if there are existing entities
-            Collection<ObjEntity> existing = map.getMappedEntities(dbEntity);
-            if (!existing.isEmpty()) {
-                loadedEntities.addAll(existing);
-                continue;
-            }
+        	
+			// TODO: performance. This is an O(n^2) search and it shows on
+			// YourKit profiles. Pre-cache mapped entities perhaps (?)
+			Collection<ObjEntity> existing = map.getMappedEntities(dbEntity);
+			if (!existing.isEmpty()) {
+				loadedEntities.addAll(existing);
+				continue;
+			}
 
             String objEntityName = DefaultUniqueNameGenerator.generate(NameCheckers.objEntity, map,
                     nameGenerator.createObjEntityName(dbEntity));

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2c06db64/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java b/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
index 42cb307..2607bcd 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
@@ -317,19 +317,26 @@ public class EntityMergeSupport {
         return missing;
     }
 
-    private Collection<DbRelationship> getIncomingRelationships(DbEntity entity) {
-        Collection<DbRelationship> incoming = new ArrayList<DbRelationship>();
-
-        for (DbEntity nextEntity : entity.getDataMap().getDbEntities()) {
-            for (DbRelationship relationship : nextEntity.getRelationships()) {
-                if (entity == relationship.getTargetEntity()) {
-                    incoming.add(relationship);
-                }
-            }
-        }
-
-        return incoming;
-    }
+	private Collection<DbRelationship> getIncomingRelationships(DbEntity entity) {
+		Collection<DbRelationship> incoming = new ArrayList<DbRelationship>();
+
+		for (DbEntity nextEntity : entity.getDataMap().getDbEntities()) {
+			for (DbRelationship relationship : nextEntity.getRelationships()) {
+
+				// TODO: PERFORMANCE 'getTargetEntity' is generally slow, called
+				// in this iterator it is showing (e.g. in YourKit profiles)..
+				// perhaps use cheaper 'getTargetEntityName()' or even better -
+				// pre-cache all relationships by target entity to avoid O(n)
+				// search ?
+				// (need to profile to prove the difference)
+				if (entity == relationship.getTargetEntity()) {
+					incoming.add(relationship);
+				}
+			}
+		}
+
+		return incoming;
+	}
 
     protected List<DbRelationship> getRelationshipsToAdd(ObjEntity objEntity) {
         List<DbRelationship> missing = new ArrayList<DbRelationship>();