]> source.dussan.org Git - jgit.git/commitdiff
Cache trustFolderStat/trustPackedRefsStat value per-instance 25/199325/3
authorNasser Grainawi <quic_nasserg@quicinc.com>
Tue, 10 Jan 2023 23:15:42 +0000 (16:15 -0700)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 13 Jan 2023 17:45:02 +0000 (18:45 +0100)
Instead of re-reading the config every time the methods using these
values were called, cache the config value at the time of instance
construction. Caching the values improves performance for each of the
method calls. These configs are set based on the filesystem storing the
repository and unlikely to change while an application is running.

Change-Id: I1cae26dad672dd28b766ac532a871671475652df
Signed-off-by: Nasser Grainawi <quic_nasserg@quicinc.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackDirectory.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

index f32909f44d23a55898ac8c720ffd6756e1516722..a7f28c67780c86d33d3ec9f1761e68ed67fc70c2 100644 (file)
@@ -63,12 +63,12 @@ class PackDirectory {
        private static final PackList NO_PACKS = new PackList(FileSnapshot.DIRTY,
                        new Pack[0]);
 
-       private final Config config;
-
        private final File directory;
 
        private final AtomicReference<PackList> packList;
 
+       private final boolean trustFolderStat;
+
        /**
         * Initialize a reference to an on-disk 'pack' directory.
         *
@@ -78,9 +78,16 @@ class PackDirectory {
         *            the location of the {@code pack} directory.
         */
        PackDirectory(Config config, File directory) {
-               this.config = config;
                this.directory = directory;
                packList = new AtomicReference<>(NO_PACKS);
+
+               // Whether to trust the pack folder's modification time. If set to false
+               // we will always scan the .git/objects/pack folder to check for new
+               // pack files. If set to true (default) we use the folder's size,
+               // modification time, and key (inode) and assume that no new pack files
+               // can be in this folder if these attributes have not changed.
+               trustFolderStat = config.getBoolean(ConfigConstants.CONFIG_CORE_SECTION,
+                               ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT, true);
        }
 
        /**
@@ -331,16 +338,6 @@ class PackDirectory {
        }
 
        boolean searchPacksAgain(PackList old) {
-               // Whether to trust the pack folder's modification time. If set
-               // to false we will always scan the .git/objects/pack folder to
-               // check for new pack files. If set to true (default) we use the
-               // lastmodified attribute of the folder and assume that no new
-               // pack files can be in this folder if his modification time has
-               // not changed.
-               boolean trustFolderStat = config.getBoolean(
-                               ConfigConstants.CONFIG_CORE_SECTION,
-                               ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT, true);
-
                return ((!trustFolderStat) || old.snapshot.isModified(directory))
                                && old != scanPacks(old);
        }
index 43ebce3918cb0b77f2cb200aa9bf7b7e16d1d0a7..d4ad190ffde56b32c3032c14d6e2a9d4ba235cb9 100644 (file)
@@ -179,6 +179,10 @@ public class RefDirectory extends RefDatabase {
 
        private List<Integer> retrySleepMs = RETRY_SLEEP_MS;
 
+       private final boolean trustFolderStat;
+
+       private final TrustPackedRefsStat trustPackedRefsStat;
+
        RefDirectory(FileRepository db) {
                final FS fs = db.getFS();
                parent = db;
@@ -190,6 +194,13 @@ public class RefDirectory extends RefDatabase {
 
                looseRefs.set(RefList.<LooseRef> emptyList());
                packedRefs.set(NO_PACKED_REFS);
+               trustFolderStat = db.getConfig()
+                               .getBoolean(ConfigConstants.CONFIG_CORE_SECTION,
+                                               ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT, true);
+               trustPackedRefsStat = db.getConfig()
+                               .getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
+                                               ConfigConstants.CONFIG_KEY_TRUST_PACKED_REFS_STAT,
+                                               TrustPackedRefsStat.UNSET);
        }
 
        Repository getRepository() {
@@ -891,16 +902,6 @@ public class RefDirectory extends RefDatabase {
        }
 
        PackedRefList getPackedRefs() throws IOException {
-               boolean trustFolderStat = getRepository().getConfig().getBoolean(
-                               ConfigConstants.CONFIG_CORE_SECTION,
-                               ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT, true);
-               TrustPackedRefsStat trustPackedRefsStat =
-                               getRepository().getConfig().getEnum(
-                                               ConfigConstants.CONFIG_CORE_SECTION,
-                                               null,
-                                               ConfigConstants.CONFIG_KEY_TRUST_PACKED_REFS_STAT,
-                                               TrustPackedRefsStat.UNSET);
-
                final PackedRefList curList = packedRefs.get();
 
                switch (trustPackedRefsStat) {