Open asafm opened 1 year ago
Nice find. I wonder if we can lazily initialize somewhere deeper down in the reservoir itself to keep the code flow the same. Something like this this: https://github.com/open-telemetry/opentelemetry-java/commit/823e46c1e5ab6efbfe3b867d24342b8b117d2c3e
I believe so.
For FixedSizeExemplarReservoir
, we can start with null value for ReservoirCell[] storage;
In offerLongMeasurement
and offerDoubleMeasurement
, I'll call ensureInitialized()
, which will check if null, and if so, init the array as the c'tor does:
this.storage = new ReservoirCell[size];
for (int i = 0; i < size; ++i) {
this.storage[i] = new ReservoirCell(clock);
}
I thought of lazy init easy item in the array, but the selector gets access to the array in full, so there is not interface to hide behind.
WDYT
I thought of lazy init easy item in the array, but the selector gets access to the array in full,
The selector? In the commit I posted above the code that iterates over the array is made to handle nullable array entries.
But I'm also fine with initializing ReservoirCell[] storage
to null. Achieves the same affect and may be a bit simpler.
Is your feature request related to a problem? Please describe.
When you create a
SdkMeterProviderBuilder
and specify anExemplarFilter
, which is off, you would expect there won't be any memory allocations made since exemplars are not being collected in effect.It happens in multiple locations, where an aggregator is created with an exemplar reservoir. In all places, it is wrapped with a filtered reservoir, but it's created either way without considering the filter might be off.
Example:
For a single aggregator with 100k attributes, it's 70 MB of memory not needed.
Describe the solution you'd like
Since the filter is not an enum, there's no way to know from it whether it's off or not. Also, some filters might not introduce any sampling for certain attributes but are not declared as off.
I suggest changing the argument of
ExemplarReservoir<T> original
inExemplarReservoir.filtered()
, to a function providing that (Supplier<ExemplarReservoir<T>>
).FilteredExemplarReservoir
methods would ensureprivate ExemplarReservoir<T> reservoir;
is initialized before use. Initialization would be done using the supplier. Lazy init.Describe alternatives you've considered None at the moment
Additional context None at the moment