Use `EnumSet` for collection of profiled types for better performance.
`RegularImmutableSet.contains()` shows up in profiles related to the footprint
of the profiler.
`EnumSet.contains()` is specialized and faster implementation than
`ImmutableSet.contains()`.
@@ -37,9 +37,11 @@ import java.lang.management.ManagementFactory;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -295,7 +297,7 @@ public final class Profiler {
}
private Clock clock;
- private ImmutableSet<ProfilerTask> profiledTasks;
+ private Set<ProfilerTask> profiledTasks;
private volatile long profileStartTime;
private volatile boolean recordAllDurations = false;
private Duration profileCpuStartTime;
@@ -442,7 +444,7 @@ public final class Profiler {
Preconditions.checkState(!isActive(), "Profiler already active");
initHistograms();
- this.profiledTasks = profiledTasks;
+ this.profiledTasks = profiledTasks.isEmpty() ? profiledTasks : EnumSet.copyOf(profiledTasks);
this.clock = clock;
this.actionCountStartTime = Duration.ofNanos(clock.nanoTime());
this.actionCountTimeSeries = new TimeSeries(actionCountStartTime, ACTION_COUNT_BUCKET_DURATION);
