Skip to content

Commit

Permalink
Optimize DefaultSynchronousMetricStorage iteration (#5183)
Browse files Browse the repository at this point in the history
* Optimize DefaultSynchronousMetricStorage iteration

* Switch to foreach
  • Loading branch information
jack-berg committed Feb 22, 2023
1 parent 411d5de commit 696d3f0
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.opentelemetry.sdk.resources.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -131,18 +130,18 @@ public MetricData collect(

// Grab aggregated points.
List<T> points = new ArrayList<>(aggregatorHandles.size());
for (Map.Entry<Attributes, AggregatorHandle<T, U>> entry : aggregatorHandles.entrySet()) {
T point = entry.getValue().aggregateThenMaybeReset(start, epochNanos, entry.getKey(), reset);
if (reset) {
aggregatorHandles.remove(entry.getKey(), entry.getValue());
// Return the aggregator to the pool.
aggregatorHandlePool.offer(entry.getValue());
}
if (point == null) {
continue;
}
points.add(point);
}
aggregatorHandles.forEach(
(attributes, handle) -> {
T point = handle.aggregateThenMaybeReset(start, epochNanos, attributes, reset);
if (reset) {
aggregatorHandles.remove(attributes, handle);
// Return the aggregator to the pool.
aggregatorHandlePool.offer(handle);
}
if (point != null) {
points.add(point);
}
});

// Trim pool down if needed. pool.size() will only exceed MAX_CARDINALITY if new handles are
// created during collection.
Expand Down

0 comments on commit 696d3f0

Please sign in to comment.