git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[EGIT PATCH 05/10] Cache commits

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Mar 11, 2007, 18:15 UTC
Message-ID
<20070311181542.18012.36508.stgit@lathund.dewire.com>
In-Reply-To
<20070311180608.18012.13767.stgit@lathund.dewire.com>

This uses more memory, but by having a WeakMap we allow the garbage collector to claim the memory if needed. This speeds up the history panel enormously, so that having the history pane connected to the selected resource is not a performance problem (except the first time the history of a resource in a projects is shown).

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/lib/Repository.java       |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index 781ad90..f7c470d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -25,6 +25,8 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
+import java.util.WeakHashMap;
 
 import org.spearce.jgit.errors.IncorrectObjectTypeException;
 import org.spearce.jgit.errors.ObjectWritingException;
@@ -45,6 +47,8 @@ public class Repository {
 
 	private WindowCache windows;
 
+	private Map cache = new WeakHashMap(30000); 
+
 	public Repository(final File d) throws IOException {
 		gitDir = d.getAbsoluteFile();
 		objectsDir = new File(gitDir, "objects");
@@ -185,12 +189,19 @@ public class Repository {
 	}
 
 	public Commit mapCommit(final ObjectId id) throws IOException {
+		Commit ret = (Commit)cache.get(id);
+		if (ret != null)
+			return ret;
+
 		final ObjectLoader or = openObject(id);
 		if (or == null)
 			return null;
 		final byte[] raw = or.getBytes();
-		if (Constants.TYPE_COMMIT.equals(or.getType()))
-			return new Commit(this, id, raw);
+		if (Constants.TYPE_COMMIT.equals(or.getType())) {
+			ret = new Commit(this, id, raw);
+			cache.put(id, ret);
+			return ret;
+		}
 		throw new IncorrectObjectTypeException(id, Constants.TYPE_COMMIT);
 	}
 
Previous: Robin RosenbergNext: Robin Rosenberg
Message 6 of 16 in “Fixes and improvement on Eclipse plugin”
  1. 00/10 Fixes and improvement on Eclipse pluginRobin Rosenberg, Mar 11, 2007
  2. 01/10 Git history refresh problemRobin Rosenberg, Mar 11, 2007
  3. 02/10 Support commit encoding headerRobin Rosenberg, Mar 11, 2007
  4. 03/10 Avoid a nullpointerexception on shutdownRobin Rosenberg, Mar 11, 2007
  5. 04/10 Speed up history by comparing tree hashes.Robin Rosenberg, Mar 11, 2007
  6. 05/10 Cache commitsRobin Rosenberg, Mar 11, 2007
  7. 06/10 Allow history listing on folders and projects.Robin Rosenberg, Mar 11, 2007
  8. 07/10 Return nothing if no version exists for a commit.Robin Rosenberg, Mar 11, 2007
  9. 08/10 Show only commits that represent changes in the history viewRobin Rosenberg, Mar 11, 2007
  10. 09/10 Hash ObjectId faster.Robin Rosenberg, Mar 11, 2007
  11. 10/10 Display distance to head in history pageRobin Rosenberg, Mar 11, 2007
  12. 0/2 Series short descriptionRobin Rosenberg, Mar 11, 2007
  13. Shawn O. PearceMar 11, 2007
  14. Robin RosenbergMar 11, 2007
  15. 1/2 Tag version 0.2.1Robin Rosenberg, Mar 11, 2007
  16. 2/2 Re-add qualfiier for development versionRobin Rosenberg, Mar 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.