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

[JGIT PATCH 5/5] UploadPack: Only recompute okToGiveUp() if bases changed

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jun 12, 2009, 23:00 UTC
Message-ID
<1244847619-7364-6-git-send-email-spearce@spearce.org>
In-Reply-To
<1244847619-7364-5-git-send-email-spearce@spearce.org>

If we get a commit we don't recognize, but we haven't added any new common bases to the commonBase set since the last time we ran the okToGiveUp() algorithm, then there is no point in running it again, as the result will not change. Instead we cache the result in a Boolean and just return the cached result until another common base can be found and added to the set.

This helps to fix a performance problem when the client is 50,000 commits ahead of the server, and keeps sending them in "have" lines, but the server doesn't recognize them. On every "have" line we will not have updated the common base, but we also aren't yet satisfied that it is OK to give up negotiation.

Between the changes introduced by the parent commit and this commit, negotiation in this case of 50,000 ahead now completes instantly, instead of taking hours.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/transport/UploadPack.java |   27 ++++++++++++++------
 1 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
index 5127dad..5c8df62 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
@@ -112,6 +112,9 @@
 	/** Objects on both sides, these don't have to be sent. */
 	private final List<RevObject> commonBase = new ArrayList<RevObject>();
 
+	/** null if {@link #commonBase} should be examined again. */
+	private Boolean okToGiveUp;
+
 	/** Marked on objects we sent in our advertisement list. */
 	private final RevFlag ADVERTISED;
 
@@ -396,15 +399,26 @@ private boolean matchHave(final ObjectId id) {
 			o.add(PEER_HAS);
 			if (o instanceof RevCommit)
 				((RevCommit) o).carry(PEER_HAS);
-			if (!o.has(COMMON)) {
-				o.add(COMMON);
-				commonBase.add(o);
-			}
+			addCommonBase(o);
 		}
 		return true;
 	}
 
+	private void addCommonBase(final RevObject o) {
+		if (!o.has(COMMON)) {
+			o.add(COMMON);
+			commonBase.add(o);
+			okToGiveUp = null;
+		}
+	}
+
 	private boolean okToGiveUp() throws PackProtocolException {
+		if (okToGiveUp == null)
+			okToGiveUp = Boolean.valueOf(okToGiveUpImp());
+		return okToGiveUp.booleanValue();
+	}
+
+	private boolean okToGiveUpImp() throws PackProtocolException {
 		if (commonBase.isEmpty())
 			return false;
 
@@ -429,10 +443,7 @@ private boolean wantSatisfied(final RevCommit want) throws IOException {
 			if (c == null)
 				break;
 			if (c.has(PEER_HAS)) {
-				if (!c.has(COMMON)) {
-					c.add(COMMON);
-					commonBase.add(c);
-				}
+				addCommonBase(c);
 				return true;
 			}
 		}
-- 
1.6.3.2.367.gf0de
Previous: Shawn O. Pearce
Message 6 of 6 in “Fix major performance problems in UploadPack”
  1. 0/5 Fix major performance problems in UploadPackShawn O. Pearce, Jun 12, 2009
  2. 1/5 Make RevTag getObject(), getName() final to prevent overridesShawn O. Pearce, Jun 12, 2009
  3. 2/5 Allow exceptions to be created with integer type codesShawn O. Pearce, Jun 12, 2009
  4. 3/5 Unify RevWalk parsing code to be more consistent across typesShawn O. Pearce, Jun 12, 2009
  5. 4/5 Change RevObject dispose() semantics to avoid reparsesShawn O. Pearce, Jun 12, 2009
  6. 5/5 UploadPack: Only recompute okToGiveUp() if bases changedShawn O. Pearce, Jun 12, 2009

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.