From ffd202ba96b1864407ee27aa07eae57791cb2696 Mon Sep 17 00:00:00 2001 From: "Andrei.Kuznetsov" Date: Fri, 28 Jun 2024 12:35:17 +0200 Subject: [PATCH] IJPL-157271: performance experiment: avoid `synchronized` in c.i.o.fileTypes.WildcardFileNameMatcher.RegexpMatcher This will produce more very short-living garbage which looks harmless. Matcher class has about 20 fields inside. Keep aside that some of them are arrays, Matcher probably occupies 100-150 bytes in the memory. I.e. there will be 150-225MB of garbage for mid-size project like idea ultimate (~1.5M files). Looks acceptable, because preliminary experiments showed that this will decrease 2nd scanning by ~10% (10sec -> 9sec) because of better parallelization when indexing on 19 threads. More parallel environments (like dev pods) should probably show even better parallelization. GitOrigin-RevId: 450ccf3105d31be2703e4da859a59f1ee6351b8e --- .../openapi/fileTypes/WildcardFileNameMatcher.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/jps/model-impl/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java b/jps/model-impl/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java index c9227994a83c..78b18d86a826 100644 --- a/jps/model-impl/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java +++ b/jps/model-impl/src/com/intellij/openapi/fileTypes/WildcardFileNameMatcher.java @@ -5,7 +5,7 @@ import com.intellij.openapi.util.text.Strings; import com.intellij.util.PatternUtil; import org.jetbrains.annotations.NotNull; -import java.util.regex.Matcher; +import java.util.regex.Pattern; public class WildcardFileNameMatcher implements FileNameMatcher { private final String myPattern; @@ -16,18 +16,15 @@ public class WildcardFileNameMatcher implements FileNameMatcher { } private static final class RegexpMatcher implements MaskMatcher { - private final Matcher myMatcher; + private final Pattern pattern; RegexpMatcher(@NotNull String pattern) { - myMatcher = PatternUtil.fromMask(pattern).matcher(""); + this.pattern = PatternUtil.fromMask(pattern); } @Override public boolean matches(final @NotNull CharSequence filename) { - synchronized (myMatcher) { - myMatcher.reset(filename); - return myMatcher.matches(); - } + return pattern.matcher(filename).matches(); } }