RFR: 8254807: Optimize startsWith() for String.substring()
Xin Liu
xliu at openjdk.java.net
Sat Oct 31 05:30:55 UTC 2020
On Sat, 31 Oct 2020 05:22:39 GMT, Xin Liu <xliu at openjdk.org> wrote:
> the optimization transforms code from s=substring(base, beg, end); s.startsWith(prefix)
> to substring(base, beg, end) | base.startsWith(prefix, beg).
>
> it reduces an use of substring. hopefully c2 optimizer can remove the used substring()
$make test TEST="micro:SubstringAndStartsWith" CONF=linux-x86_64-server-release
Benchmark (substrLength) Mode Cnt Score Error Units
SubstringAndStartsWith.substr2StartsWith 1 thrpt 100 140630.609 ? 9.404 ops/ms
SubstringAndStartsWith.substr2StartsWith 8 thrpt 100 140634.988 ? 7.704 ops/ms
SubstringAndStartsWith.substr2StartsWith 32 thrpt 100 135812.111 ? 4687.410 ops/ms
SubstringAndStartsWith.substr2StartsWith 128 thrpt 100 140644.499 ? 7.856 ops/ms
SubstringAndStartsWith.substr2StartsWith 256 thrpt 100 140640.309 ? 8.535 ops/ms
SubstringAndStartsWith.substr2StartsWith 512 thrpt 100 140643.976 ? 8.168 ops/ms
SubstringAndStartsWith.substr2StartsWith_noalloc 1 thrpt 100 158672.117 ? 8.510 ops/ms
SubstringAndStartsWith.substr2StartsWith_noalloc 8 thrpt 100 158673.989 ? 10.198 ops/ms
SubstringAndStartsWith.substr2StartsWith_noalloc 32 thrpt 100 158677.660 ? 8.987 ops/ms
SubstringAndStartsWith.substr2StartsWith_noalloc 128 thrpt 100 153677.095 ? 5418.718 ops/ms
SubstringAndStartsWith.substr2StartsWith_noalloc 256 thrpt 100 158668.766 ? 9.138 ops/ms
SubstringAndStartsWith.substr2StartsWith_noalloc 512 thrpt 100 152544.827 ? 5922.157 ops/ms
Finished running test 'micro:SubstringAndStartsWith'
Test report is stored in build/linux-x86_64-server-release/test-results/micro_SubstringAndStartsWith
The micro demonstrates the optimization removes substring() and the throughput is constant value.
it's still slight lower than handcrafted version `substr2StartsWith_noalloc` because the later doesn't need to check complete bound check.
-------------
PR: https://git.openjdk.java.net/jdk/pull/974
More information about the hotspot-compiler-dev
mailing list