From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: spearce@spearce.org
Subject: [PATCH 2/4] Rework tree/commit cache
Date: Sun, 18 Mar 2007 23:16:01 +0100 [thread overview]
Message-ID: <20070318221601.24742.14256.stgit@lathund.dewire.com> (raw)
In-Reply-To: <20070318220711.24742.90943.stgit@lathund.dewire.com>
We now use SoftRefernces to hold the value objects and reuse
the object id's as cache keys. Seems to work much better, i.e.
the gc only throws out stuff from the cache when memory is
tight, rather than at the first opportunity.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../src/org/spearce/jgit/lib/Repository.java | 30 +++++++++++++++--------
1 files changed, 20 insertions(+), 10 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 d3b2178..c7c47ae 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -23,6 +23,8 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
@@ -190,19 +192,24 @@ public class Repository {
}
public Commit mapCommit(final ObjectId id) throws IOException {
- Commit ret = (Commit)commitCache.get(id);
- if (ret != null)
- return ret;
+// System.out.println("commitcache.size="+commitCache.size());
+ Reference retr = (Reference)commitCache.get(id);
+ if (retr != null) {
+ Commit ret = (Commit)retr.get();
+ if (ret != null)
+ return ret;
+ System.out.println("Found a null id, size was "+commitCache.size());
+ }
final ObjectLoader or = openObject(id);
if (or == null)
return null;
final byte[] raw = or.getBytes();
if (Constants.TYPE_COMMIT.equals(or.getType())) {
- ret = new Commit(this, id, raw);
+ Commit ret = new Commit(this, id, raw);
// The key must not be the referenced strongly
// by the value in WeakHashMaps
- commitCache.put(new ObjectId(id.getBytes()), ret);
+ commitCache.put(id, new SoftReference(ret));
return ret;
}
throw new IncorrectObjectTypeException(id, Constants.TYPE_COMMIT);
@@ -214,17 +221,20 @@ public class Repository {
}
public Tree mapTree(final ObjectId id) throws IOException {
- Tree ret = (Tree)treeCache.get(id);
- if (ret != null)
- return ret;
+ Reference wret = (Reference)treeCache.get(id);
+ if (wret != null) {
+ Tree ret = (Tree)wret.get();
+ if (ret != null)
+ return ret;
+ }
final ObjectLoader or = openObject(id);
if (or == null)
return null;
final byte[] raw = or.getBytes();
if (Constants.TYPE_TREE.equals(or.getType())) {
- ret = new Tree(this, id, raw);
- treeCache.put(new ObjectId(id.getBytes()), ret);
+ Tree ret = new Tree(this, id, raw);
+ treeCache.put(id, new SoftReference(ret));
return ret;
}
if (Constants.TYPE_COMMIT.equals(or.getType()))
next prev parent reply other threads:[~2007-03-18 22:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-18 22:15 [PATCH 0/4] Eclipse (EGIT) Structured compare Robin Rosenberg
2007-03-18 22:15 ` [PATCH 1/4] Cache tree ObjectId's too Robin Rosenberg
2007-03-18 22:16 ` Robin Rosenberg [this message]
2007-03-18 22:16 ` [PATCH 3/4] Decode message when encoding line is present Robin Rosenberg
2007-03-18 22:16 ` [PATCH 4/4] Add support for structured comparison Robin Rosenberg
2007-03-19 2:21 ` [PATCH 0/4] Eclipse (EGIT) Structured compare Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070318221601.24742.14256.stgit@lathund.dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).