diff options
author | Kaushik Lingarkar <quic_kaushikl@quicinc.com> | 2021-11-29 12:14:56 -0800 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2021-12-03 22:06:46 +0100 |
commit | f829f5f838e0f9c17373ea6cb3407976a8f395ff (patch) | |
tree | 5ecf9c29ecda7b3ae0aabc10b7fe1c34af785665 /org.eclipse.jgit/src/org/eclipse | |
parent | 5606a53151e8b9b4785e5c01513eb331998b8278 (diff) | |
download | jgit-f829f5f838e0f9c17373ea6cb3407976a8f395ff.tar.gz jgit-f829f5f838e0f9c17373ea6cb3407976a8f395ff.zip |
RefDirectory.scanRef: Re-use file existence check done in snapshot creation
Return immediately in scanRef if the loose ref was identified as
missing when a snapshot was attempted for the ref. This will help
performance of scanRef when the ref is packed but has a corresponding
empty dir in 'refs/'.
For example, consider the case where we create 50k sharded refs in
a new namespace called 'new-refs' using an atomic 'BatchRefUpdate'.
The refs are named like 'refs/new-refs/01/1/1', 'refs/new-refs/01/1/2',
'refs/new-refs/01/1/3' and so on. After the refs are created, the
'new-refs' namespace looks like below:
$ find refs/new-refs -type f | wc -l
0
$ find refs/new-refs -type d | wc -l
5101
At this point, an 'exactRef' call on each of the 50k refs without
this change takes ~2.5s, where as with this change it takes ~1.5s.
Change-Id: I926bc41b9ae89a1a792b1b5ec9a17b05271c906b
Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java | 9 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java index 487ae06014..654e98d817 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java @@ -439,6 +439,15 @@ public class FileSnapshot { return equals(other); } + /** + * Check if the file exists + * + * @return true if the file exists + */ + public boolean fileExists() { + return !MISSING_FILEKEY.equals(this.fileKey); + } + /** {@inheritDoc} */ @Override public int hashCode() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index f7a52a54b6..c15e26cd43 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -1103,6 +1103,10 @@ public class RefDirectory extends RefDatabase { final int limit = 4096; final byte[] buf; FileSnapshot otherSnapshot = FileSnapshot.save(path); + if (!otherSnapshot.fileExists()) { + return null; + } + try { buf = IO.readSome(path, limit); } catch (FileNotFoundException noFile) { |