diff --git a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStackTracesAction.java b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStackTracesAction.java index ff9ad2e4f2e38..94cc8631b37b8 100644 --- a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStackTracesAction.java +++ b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStackTracesAction.java @@ -483,11 +483,8 @@ private class StackTraceHandler { private final GetStackTracesResponseBuilder responseBuilder; private final ActionListener submitListener; private final Map stackTracePerId; - // sort items lexicographically to access Lucene's term dictionary more efficiently when issuing an mget request. - // The term dictionary is lexicographically sorted and using the same order reduces the number of page faults - // needed to load it. - private final Set stackFrameIds = new ConcurrentSkipListSet<>(); - private final Set executableIds = new ConcurrentSkipListSet<>(); + private final Set stackFrameIds; + private final Set executableIds; private final AtomicInteger totalFrames = new AtomicInteger(); private final StopWatch watch = new StopWatch("retrieveStackTraces"); private final StopWatch hostsWatch = new StopWatch("retrieveHostMetadata"); @@ -506,6 +503,9 @@ private StackTraceHandler( this.submitTask = submitTask; this.clusterState = clusterState; this.stackTracePerId = new ConcurrentHashMap<>(stackTraceCount); + // pre-size with a bit of headroom so the collection isn't resized too often + this.stackFrameIds = Collections.newSetFromMap(new ConcurrentHashMap<>(stackTraceCount * 5)); + this.executableIds = Collections.newSetFromMap(new ConcurrentHashMap<>(stackTraceCount)); this.expectedResponses = new AtomicInteger(expectedResponses); this.client = client; this.responseBuilder = responseBuilder;