On Wed, May 13, 2015 at 2:25 PM, Ivan Gerasimov <ivan.gerasi...@oracle.com> wrote:
> > Benchmark Mode Cnt Score Error Units > MyBenchmark.testMethod_1 thrpt 60 1132911599.680 ± 42375177.640 ops/s > MyBenchmark.testMethod_2 thrpt 60 813737659.576 ± 14226427.823 ops/s > MyBenchmark.testMethod_3 thrpt 60 810406621.145 ± 12316864.045 ops/s > > The plain old ||-combined check was faster in this round. > Some other tests showed different results. > The speed seems to depend on the scope of the checked variables and > complexity of the expressions to calculate. > However, I still don't have a clear understanding of all the aspects we > need to pay attention to when doing such optimizations. > I'm not sure, but the only thing that could explain such a huge performance gap is that hotspot was able to determine at jit time that some of the comparisons did not need to be performed at all. If true, is this cheating or not? (you could retry with -Xint) One of the ideas is to separate hot and cold code (hotspot does not yet split code inside a single method) so that hotspot is more likely to inline, so that hotspot is more likely to optimize, and optimizing beginIndex < 0 away entirely is much easier than my more complex expression. So yeah, I could be persuaded that keeping beginIndex < 0 as an independent expression likely to be eliminated. Micro-optimizing is hard, but for the very core of the platform, important (more than readability). One of these days I have to learn how to write a jmh benchmark.