perf: DirFilterEvents.findDirRpos: single map access on fast path
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2023-08-23 18:52:38 +02:00
parent b3e8cc22cf
commit d02e9f697a
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 6 additions and 2 deletions

View File

@ -113,8 +113,12 @@ public enum DirFilterEvents implements UserResourceEvents.Open, UserResourceEven
CachedPackState state = MetaCache.getState(MetaCache.getKeyByPack(pack));
var cache = state.cachedDirRPOs();
// This is outside computeIfAbsent because it could cause modification of the map, which is unsupported within it
if (cache.containsKey(path)) return cache.get(path);
{
// This is outside computeIfAbsent because it could cause modification of the map, which is unsupported within it
List<DirRpo> cached = cache.get(path);
if (cached != null) return cached;
}
List<DirRpo> parentRPOs = findDirRpos(pack, parent(path));
synchronized (cache) { // This is synchronized as multiple resources might be accessed at the same time, potentially causing a CME here
return cache.computeIfAbsent(path, $ -> {