On Fri, 7 Jul 2023 16:02:57 GMT, Sergey Kuksenko <skukse...@openjdk.org> wrote:
>> Hi, >> I'm not sure if I understand this improvement correctly. >> I'm not quite familiar with JMH and it's annotations, but seems to me, the >> change from `@State(Scope.Benchmark)` to `@State(Scope.Thread)` should not >> improve the performance by reducing cache contention, as in the jmh doc it >> says "State objects are usually injected into Benchmark methods as >> ***arguments***, and JMH takes care of their instantiation and sharing.", >> this seems mean that @State only matters when the annotated class is used as >> a parameter of a @Benchmark method, but in the tests you modifed, seems >> there is no such use case. >> Please also check the sample usages at >> https://github.com/openjdk/jmh/blob/master/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_03_States.java. > > @Hamlin-Li > The PR is fully correct. > Don't forget, every Java instance method has a specific argument which called > "this". That is why @State annotation is working. @kuksenko @swati-sha Thanks for explanation. I can understand what you said. But I'm still not quite sure, as I remember jmh does some code manipulation or instrumentation at source code (or bytecode level?), so the jmh test code you write or see might not be the exact code to be executed at runtime. It's better to be reviewed further by some one more familiar with jmh, or could you add some data comparing the performance difference, so we can tell it easily? ------------- PR Comment: https://git.openjdk.org/jdk/pull/14746#issuecomment-1628469975