Cache trustFolderStat/trustPackedRefsStat value per-instance

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>
This commit is contained in:
Nasser Grainawi 2023-01-10 16:15:42 -07:00 committed by Matthias Sohn
parent fed1a54935
commit 21b2aef0aa
2 changed files with 21 additions and 23 deletions

View 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 @@ private boolean doLogExponentialBackoff(int n) {
}
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);
}

View 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 @@ else if (0 <= (idx = packed.find(dst.getName())))
}
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) {