RFR: 8294698: Remove unused 'checkedExceptions' param from MethodAccessorGenerator.generateMethod()
Сергей Цыпанов
duke at openjdk.org
Mon Oct 3 08:07:27 UTC 2022
On Sun, 2 Oct 2022 22:16:46 GMT, Claes Redestad <redestad at openjdk.org> wrote:
>> `checkedExceptions` param of `MethodAccessorGenerator.generateMethod()` is unused and should be removed in order to prevent allocations from `Method.getExceptionTypes()`
>
> Seems reasonable, although these generators should only rarely be used when doing reflection. I'm curious if you have some test or micro where the improvement shows?
@cl4es this code is frequently invoked in Spring-based applications at start-up time. I couldn't design the benchmark for this particular case, assuming that in majority of cases `Method.getExceptionTypes()` returns a copy of an empty array I think we save about 12 ns and 16 bytes:
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(value = Mode.AverageTime)
public class ArrayCloneBenchmark {
private final Object[] array = new Object[0];
@Benchmark
public Object[] cloneArray() {
return array.clone();
}
}
Benchmark Mode Cnt Score Error Units
ArrayCloneBenchmark.cloneArray avgt 20 12,713 ± 0,484 ns/op
ArrayCloneBenchmark.cloneArray:·gc.alloc.rate avgt 20 800,247 ± 29,584 MB/sec
ArrayCloneBenchmark.cloneArray:·gc.alloc.rate.norm avgt 20 16,004 ± 0,001 B/op
ArrayCloneBenchmark.cloneArray:·gc.churn.G1_Eden_Space avgt 20 804,623 ± 38,424 MB/sec
ArrayCloneBenchmark.cloneArray:·gc.churn.G1_Eden_Space.norm avgt 20 16,091 ± 0,455 B/op
ArrayCloneBenchmark.cloneArray:·gc.churn.G1_Survivor_Space avgt 20 0,006 ± 0,002 MB/sec
ArrayCloneBenchmark.cloneArray:·gc.churn.G1_Survivor_Space.norm avgt 20 ≈ 10⁻⁴ B/op
ArrayCloneBenchmark.cloneArray:·gc.count avgt 20 286,000 counts
ArrayCloneBenchmark.cloneArray:·gc.time avgt 20 171,000 ms
-------------
PR: https://git.openjdk.org/jdk/pull/10526
More information about the core-libs-dev
mailing list