From cb627817801b657a7711ab0826e7e7bdb6f5bb77 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 2 May 2026 01:07:36 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20regex=20caching?= =?UTF-8?q?=20in=20TestFolderPathPattern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced synchronized LRUCache with a lock-free ConcurrentHashMap. This prevents blocking across threads when multiple test paths evaluate regular expressions concurrently. Given that workspace configurations are static, cache evictions are unnecessary, rendering the LRU bound superfluous. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- .../core/matching/TestFolderPathPattern.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/org.moreunit.core/src/org/moreunit/core/matching/TestFolderPathPattern.java b/org.moreunit.core/src/org/moreunit/core/matching/TestFolderPathPattern.java index 3e9c1b28..3395e175 100644 --- a/org.moreunit.core/src/org/moreunit/core/matching/TestFolderPathPattern.java +++ b/org.moreunit.core/src/org/moreunit/core/matching/TestFolderPathPattern.java @@ -21,7 +21,15 @@ public class TestFolderPathPattern { - private static final Map PATTERN_CACHE = new LRUCache(500); + /* + * ⚡ Bolt Performance Optimization + * + * 💡 What: Upgraded the synchronized PATTERN_CACHE lookup to avoid synchronization bottlenecks. + * 🎯 Why: Instead of block-synchronizing the LRUCache, we use a ConcurrentHashMap for highly concurrent, lock-free pattern reads. To bound memory, we do not need the LRUCache eviction logic because the number of distinct path templates is statically limited by the user's workspace configuration, avoiding cache eviction overhead altogether. + * 📊 Impact: O(1) lock-free regex caching matching across multiple concurrent file matches. + * 🔬 Measurement: Reduced blocking threads inside `resolveGroups`. + */ + private static final Map PATTERN_CACHE = new java.util.concurrent.ConcurrentHashMap(); public static final String SRC_PROJECT_VARIABLE = "${srcProject}"; @@ -203,19 +211,12 @@ private String resolveGroups(String path, String tplWithGroups, String tplWithRe { String result = tplWithRefs; - Pattern pattern; - synchronized (PATTERN_CACHE) - { - pattern = PATTERN_CACHE.get(tplWithGroups); - } + Pattern pattern = PATTERN_CACHE.get(tplWithGroups); if(pattern == null) { pattern = Pattern.compile(tplWithGroups); - synchronized (PATTERN_CACHE) - { - PATTERN_CACHE.put(tplWithGroups, pattern); - } + PATTERN_CACHE.putIfAbsent(tplWithGroups, pattern); } Matcher matcher = pattern.matcher(path);