git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 5/9] Arrange pack files in recency order to improve quick hits
Date: Wed, 11 Feb 2009 18:36:55 -0800	[thread overview]
Message-ID: <1234406219-19547-6-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1234406219-19547-5-git-send-email-spearce@spearce.org>

Packs with newer modification dates are more likely to contain data
related to recent commits, and thus will have a better probability
of containing an object we care about when we are looking only at
recent history.

In some cases, this may permit JGit to avoid reading a very large
historical pack's index file into memory if the only data we ever
need is available in newer pack files.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/lib/PackFile.java         |   11 +++++++++++
 .../src/org/spearce/jgit/lib/Repository.java       |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java
index 3542560..7a16bf7 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java
@@ -43,6 +43,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.Iterator;
 import java.util.zip.CRC32;
 import java.util.zip.CheckedOutputStream;
@@ -57,10 +58,19 @@
  * objects are similar.
  */
 public class PackFile implements Iterable<PackIndex.MutableEntry> {
+	/** Sorts PackFiles to be most recently created to least recently created. */
+	public static Comparator<PackFile> SORT = new Comparator<PackFile>() {
+		public int compare(final PackFile a, final PackFile b) {
+			return b.packLastModified - a.packLastModified;
+		}
+	};
+
 	private final File idxFile;
 
 	private final WindowedFile pack;
 
+	private int packLastModified;
+
 	private PackIndex loadedIdx;
 
 	private PackReverseIndex reverseIdx;
@@ -75,6 +85,7 @@
 	 */
 	public PackFile(final File idxFile, final File packFile) {
 		this.idxFile = idxFile;
+		this.packLastModified = (int) (packFile.lastModified() >> 10);
 		pack = new WindowedFile(packFile) {
 			@Override
 			protected void onOpen() throws IOException {
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 b9c7b2e..96c62df 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -823,6 +823,7 @@ public void scanForPacks() {
 			scanForPacks(new File(d, "pack"), p);
 		final PackFile[] arr = new PackFile[p.size()];
 		p.toArray(arr);
+		Arrays.sort(arr, PackFile.SORT);
 		synchronized (this) {
 			packFileList = arr;
 		}
-- 
1.6.2.rc0.204.gf6b427

  reply	other threads:[~2009-02-12  2:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-12  2:36 [JGIT PATCH 0/9] Misc. pack code cleanups Shawn O. Pearce
2009-02-12  2:36 ` [JGIT PATCH 1/9] Remove the Repository parameter from PackFile's constructor Shawn O. Pearce
2009-02-12  2:36   ` [JGIT PATCH 2/9] Remove dead stats code from WindowCache Shawn O. Pearce
2009-02-12  2:36     ` [JGIT PATCH 3/9] Document why WindowFile's hash is *31 Shawn O. Pearce
2009-02-12  2:36       ` [JGIT PATCH 4/9] Allow PackFile to lazily load its PackIndex on first demand Shawn O. Pearce
2009-02-12  2:36         ` Shawn O. Pearce [this message]
2009-02-12  2:36           ` [JGIT PATCH 6/9] Rename readPackHeader() to be onOpenPack() Shawn O. Pearce
2009-02-12  2:36             ` [JGIT PATCH 7/9] Validate the pack's footer checksum matches that in the index Shawn O. Pearce
2009-02-12  2:36               ` [JGIT PATCH 8/9] Remove yet another legacy StGit utility function Shawn O. Pearce
2009-02-12  2:36                 ` [JGIT PATCH 9/9] Make pack.indexversion config option default to version 2 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=1234406219-19547-6-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    /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).