Precompile exclusion patterns for better performance

The exclusion patterns are matched against every metric name and we have
>100 metrics. Just using String.match is expensive because it first
compiles the pattern and then performs matching. Improve performance by
precompiling all exclusion patterns.

Change-Id: I1326697345faa3b9812a45ee24fb669f4a8d7c76
diff --git a/src/main/java/com/googlesource/gerrit/plugins/metricsreporterjmx/GerritJmxReporter.java b/src/main/java/com/googlesource/gerrit/plugins/metricsreporterjmx/GerritJmxReporter.java
index c845362..a3f9e7d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/metricsreporterjmx/GerritJmxReporter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/metricsreporterjmx/GerritJmxReporter.java
@@ -14,13 +14,17 @@
 
 package com.googlesource.gerrit.plugins.metricsreporterjmx;
 
+import static java.util.stream.Collectors.toList;
+
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.jmx.JmxReporter;
 import com.google.gerrit.extensions.annotations.Listen;
 import com.google.gerrit.extensions.events.LifecycleListener;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
+import java.util.List;
 import java.util.function.Predicate;
+import java.util.regex.Pattern;
 
 @Listen
 @Singleton
@@ -29,8 +33,9 @@
 
   @Inject
   public GerritJmxReporter(MetricRegistry registry, Configuration config) {
+    List<Pattern> excludes = config.getExcludes().stream().map(Pattern::compile).collect(toList());
     Predicate<String> exclusionFilter =
-        s -> config.getExcludes().stream().anyMatch(e -> s.matches(e));
+        s -> excludes.stream().anyMatch(e -> e.matcher(s).matches());
     this.reporter =
         JmxReporter.forRegistry(registry).filter((n, m) -> !exclusionFilter.test(n)).build();
   }