RFR: 8071571: Move substring of same string to slow path

Vitaly Davidovich vitalyd at gmail.com
Wed May 13 23:06:33 UTC 2015

Why not look at the generated asm and not guess? :) The branch avoiding
versions may cause data dependence hazards whereas the branchy one just has
branches but assuming perfectly predicted (and microbenchmarks typically
are) can pipeline through.  Ivan, could you please post the asm here?
Assuming you guys are interested in investigating this further.

sent from my phone
On May 13, 2015 6:51 PM, "Martin Buchholz" <martinrb at google.com> wrote:

> On Wed, May 13, 2015 at 2:25 PM, Ivan Gerasimov <ivan.gerasimov at 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.

More information about the core-libs-dev mailing list