Optimize DefaultSynchronousMetricStorage iteration (#5183)
* Optimize DefaultSynchronousMetricStorage iteration * Switch to foreach
This commit is contained in:
parent
411d5dee28
commit
696d3f0833
|
|
@ -22,7 +22,6 @@ import io.opentelemetry.sdk.metrics.internal.view.AttributesProcessor;
|
||||||
import io.opentelemetry.sdk.resources.Resource;
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
@ -131,18 +130,18 @@ public final class DefaultSynchronousMetricStorage<T extends PointData, U extend
|
||||||
|
|
||||||
// Grab aggregated points.
|
// Grab aggregated points.
|
||||||
List<T> points = new ArrayList<>(aggregatorHandles.size());
|
List<T> points = new ArrayList<>(aggregatorHandles.size());
|
||||||
for (Map.Entry<Attributes, AggregatorHandle<T, U>> entry : aggregatorHandles.entrySet()) {
|
aggregatorHandles.forEach(
|
||||||
T point = entry.getValue().aggregateThenMaybeReset(start, epochNanos, entry.getKey(), reset);
|
(attributes, handle) -> {
|
||||||
|
T point = handle.aggregateThenMaybeReset(start, epochNanos, attributes, reset);
|
||||||
if (reset) {
|
if (reset) {
|
||||||
aggregatorHandles.remove(entry.getKey(), entry.getValue());
|
aggregatorHandles.remove(attributes, handle);
|
||||||
// Return the aggregator to the pool.
|
// Return the aggregator to the pool.
|
||||||
aggregatorHandlePool.offer(entry.getValue());
|
aggregatorHandlePool.offer(handle);
|
||||||
}
|
|
||||||
if (point == null) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
if (point != null) {
|
||||||
points.add(point);
|
points.add(point);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Trim pool down if needed. pool.size() will only exceed MAX_CARDINALITY if new handles are
|
// Trim pool down if needed. pool.size() will only exceed MAX_CARDINALITY if new handles are
|
||||||
// created during collection.
|
// created during collection.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue