]> source.dussan.org Git - jgit.git/commitdiff
Reduce memory held and speed up DfsGarbageCollector. 51/9851/2
authorColby Ranger <cranger@google.com>
Tue, 22 Jan 2013 22:54:05 +0000 (14:54 -0800)
committerColby Ranger <cranger@google.com>
Tue, 22 Jan 2013 23:25:15 +0000 (15:25 -0800)
getObjectList() returns a list of ObjectToPack. These can hold on to a
lot of memory. Furthermore, binary searching for objects in a sorted
array can be slow. Improve the speed and reduce the memory by creating a
copy of the ObjectId and inserting it into an ObjectIdOwnerMap.

Change-Id: Ib5aa5b7447e05938b47fa55812a87b9872c20ea7

org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsGarbageCollector.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

index 21f01ad6b43dbf248efcba7726724d363cf1cb72..76fb521a62d8d7d45efdfa1f9daa972380450c0c 100644 (file)
@@ -61,6 +61,7 @@ import org.eclipse.jgit.lib.AnyObjectId;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.NullProgressMonitor;
 import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectIdOwnerMap;
 import org.eclipse.jgit.lib.ProgressMonitor;
 import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.revwalk.RevWalk;
@@ -332,10 +333,11 @@ public class DfsGarbageCollector {
                        out.close();
                }
 
-               final List<ObjectId> packedObjs = pw.getObjectList();
+               final ObjectIdOwnerMap<ObjectIdOwnerMap.Entry> packedObjs = pw
+                               .getObjectSet();
                newPackObj.add(new PackWriter.ObjectIdSet() {
                        public boolean contains(AnyObjectId objectId) {
-                               return 0 <= Collections.binarySearch(packedObjs, objectId);
+                               return packedObjs.contains(objectId);
                        }
                });
 
index b199d4feef2d55960d0475e1fca3f21597eeb689..1cf17812892c5911115f9e0a82ce411184a4fc09 100644 (file)
@@ -519,8 +519,7 @@ public class PackWriter {
        }
 
        /**
-        * Returns the object ids in the pack file that was created by this writer,
-        * sorted by name.
+        * Returns the object ids in the pack file that was created by this writer.
         *
         * This method can only be invoked after
         * {@link #writePack(ProgressMonitor, ProgressMonitor, OutputStream)} has
@@ -530,13 +529,23 @@ public class PackWriter {
         * @throws IOException
         *             a cached pack cannot supply its object ids.
         */
-       public List<ObjectId> getObjectList() throws IOException {
+       public ObjectIdOwnerMap<ObjectIdOwnerMap.Entry> getObjectSet()
+                       throws IOException {
                if (!cachedPacks.isEmpty())
                        throw new IOException(
                                        JGitText.get().cachedPacksPreventsListingObjects);
 
-               return Collections.unmodifiableList(
-                               (List<? extends ObjectId>) sortByName());
+               ObjectIdOwnerMap<ObjectIdOwnerMap.Entry> objs = new ObjectIdOwnerMap<
+                               ObjectIdOwnerMap.Entry>();
+               for (BlockList<ObjectToPack> objList : objectsLists) {
+                       if (objList != null) {
+                               for (ObjectToPack otp : objList)
+                                       objs.add(new ObjectIdOwnerMap.Entry(otp) {
+                                               // A new entry that copies the ObjectId
+                                       });
+                       }
+               }
+               return objs;
        }
 
        /**