Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Back port] 8310929: Optimization for integer/long toString #682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wenshao
Copy link

@wenshao wenshao commented Oct 5, 2023

原来的实现需要两次查表Integer.DigitTens/DigitOnes,新的实现只需要查表一次DecimalDigits#DIGITS,组合Unsafe.putShortUnaligned一次put两个数字,可以提升性能。

@kuaiwei
Copy link
Collaborator

kuaiwei commented Oct 13, 2023

原来的实现需要两次查表Integer.DigitTens/DigitOnes,新的实现只需要查表一次DecimalDigits#DIGITS,组合Unsafe.putShortUnaligned一次put两个数字,可以提升性能。

能提供一个性能测试案例吗?

@kuaiwei kuaiwei assigned kuaiwei and unassigned kuaiwei Oct 13, 2023
@wenshao
Copy link
Author

wenshao commented Oct 23, 2023

已经补上,dragoonwell11下怎么跑性能测试?

bash configure --with-jmh=build/jmh/jars

configure: error: unrecognized options: --with-jmh
configure exiting with result code 1

@wenshao
Copy link
Author

wenshao commented Oct 24, 2023

openjdk/jdk#14699

The performance test results of the latest version (PR Update 20 c0f42a7c ) are as follows:

1. aliyun_ecs_c8i.xlarge

  • cpu : intel xeon sapphire rapids (x64)
-Benchmark               (size)  Mode  Cnt  Score   Error  Units (baseline)
-Integers.toStringBig       500  avgt   15  6.800 ? 0.022  us/op
-Integers.toStringSmall     500  avgt   15  4.792 ? 0.021  us/op
-Integers.toStringTiny      500  avgt   15  3.757 ? 0.081  us/op

+Benchmark               (size)  Mode  Cnt  Score   Error  Units (PR Update 20 c0f42a7c)
+Integers.toStringBig       500  avgt   15  5.894 ? 0.046  us/op (+15.37%)
+Integers.toStringSmall     500  avgt   15  4.027 ? 0.012  us/op (+18.99%)
+Integers.toStringTiny      500  avgt   15  3.491 ? 0.090  us/op (+7.61%)

-Benchmark            (size)  Mode  Cnt  Score   Error  Units (baseline)
-Longs.toStringBig       500  avgt   15  9.213 ? 0.019  us/op
-Longs.toStringSmall     500  avgt   15  4.550 ? 0.016  us/op

+Benchmark            (size)  Mode  Cnt  Score   Error  Units (PR Update 20 c0f42a7c)
+Longs.toStringBig       500  avgt   15  7.507 ? 0.011  us/op (+22.72%)
+Longs.toStringSmall     500  avgt   15  3.967 ? 0.021  us/op (+14.69%)

-Benchmark                            Mode  Cnt   Score   Error  Units (baseline)
-StringBuilders.toStringCharWithInt8  avgt   15  89.187 ? 0.236  ns/op

+Benchmark                            Mode  Cnt   Score   Error  Units (PR Update 20 c0f42a7c)
+StringBuilders.toStringCharWithInt8  avgt   15  36.125 ? 0.309  ns/op (+146.88%)

2. aliyun_ecs_c8y.xlarge

  • cpu : aliyun yitian 710 (aarch64)
-Benchmark               (size)  Mode  Cnt   Score   Error  Units (baseline)
-Integers.toStringBig       500  avgt   15  11.649 ? 0.011  us/op
-Integers.toStringSmall     500  avgt   15   6.985 ? 0.018  us/op
-Integers.toStringTiny      500  avgt   15   5.972 ? 0.013  us/op

+Benchmark               (size)  Mode  Cnt  Score   Error  Units (PR Update 20 c0f42a7c)
+Integers.toStringBig       500  avgt   15  8.957 ? 0.026  us/op (+30.05%)
+Integers.toStringSmall     500  avgt   15  6.136 ? 0.018  us/op (+13.83%)
+Integers.toStringTiny      500  avgt   15  5.753 ? 0.026  us/op (+3.80%)

-Benchmark            (size)  Mode  Cnt   Score   Error  Units (baseline)
-Longs.toStringBig       500  avgt   15  14.568 ? 0.021  us/op
-Longs.toStringSmall     500  avgt   15   7.250 ? 0.023  us/op

+Benchmark            (size)  Mode  Cnt   Score   Error  Units (PR Update 20 c0f42a7c)
+Longs.toStringBig       500  avgt   15  13.401 ? 0.012  us/op (+8.70%)
+Longs.toStringSmall     500  avgt   15   6.031 ? 0.018  us/op (+20.21%)

-Benchmark                            Mode  Cnt   Score   Error  Units (baseline)
-StringBuilders.toStringCharWithInt8  avgt   15  52.484 ? 0.534  ns/op

+Benchmark                            Mode  Cnt   Score   Error  Units (PR Update 20 c0f42a7c)
+StringBuilders.toStringCharWithInt8  avgt   15  40.410 ? 0.348  ns/op (+29.87%)

3. MacBookPro M1 Pro

-Benchmark               (size)  Mode  Cnt   Score   Error  Units (baseline)
-Integers.toStringBig       500  avgt   15  18.483 ± 2.771  us/op
-Integers.toStringSmall     500  avgt   15   4.435 ± 0.067  us/op
-Integers.toStringTiny      500  avgt   15   2.382 ± 0.063  us/op

+Benchmark               (size)  Mode  Cnt  Score   Error  Units (PR Update 20 c0f42a7c)
+Integers.toStringBig       500  avgt   15  5.392 ? 0.016  us/op (+242.78%)
+Integers.toStringSmall     500  avgt   15  3.201 ? 0.024  us/op (+38.55%)
+Integers.toStringTiny      500  avgt   15  2.141 ? 0.021  us/op (+11.25%)

-Benchmark            (size)  Mode  Cnt  Score   Error  Units (baseline)
-Longs.toStringBig       500  avgt   15  8.336 ± 0.025  us/op
-Longs.toStringSmall     500  avgt   15  4.389 ± 0.018  us/op

+Benchmark            (size)  Mode  Cnt  Score   Error  Units (PR Update 20 c0f42a7c)
+Longs.toStringBig       500  avgt   15  7.706 ? 0.015  us/op (+8.17%)
+Longs.toStringSmall     500  avgt   15  3.094 ? 0.021  us/op (+41.85%)

-Benchmark                            Mode  Cnt    Score    Error  Units (baseline)
-StringBuilders.toStringCharWithInt8  avgt   15  124.316 ± 61.017  ns/op

+Benchmark                            Mode  Cnt   Score    Error  Units (PR Update 20 c0f42a7c)
+StringBuilders.toStringCharWithInt8  avgt   15  44.497 ? 29.741  ns/op (+179.38%)

@JoshuaZhuwj
Copy link
Collaborator

Hi wenshao,
I have three minor comments.

  1. It would be better to submit your changes as the original commits. I mean separating these changes into two commits (JDK-8310929 and JDK-8315970). In this way, changes will be easier to track and manage.
  2. The git commits message should be "[Backport] 8310929: Optimization for Integer.toString" instead of "back port from openjdk, optimization for integer/long toString" otherwise your commits will be blocked by Dragonwell CI tests due to improper commit title.
  3. Currently there exist two other issues (JDK-8316582 and JDK-8317329) filed against 8310929. Do we need to incorporate these new changes?

@wenshao
Copy link
Author

wenshao commented Oct 26, 2023

This BackPort PR merges three PRs (8317329, 8310929, 8317329)

@wenshao
Copy link
Author

wenshao commented Oct 27, 2023

这个PR合并了原来三个PR:

  1. 8310929: Optimization for Integer.toString openjdk/jdk#14699 我提交的第一个版本,这个版本性能比较好,但因为使用了ByteArrayLittleEndian,会影响JVM启动性能。
  2. 8315970: Big-endian issues after JDK-8310929 openjdk/jdk#15652 我提交的第二个版本,修复StringUTF16 BigEndian机器下的问题
  3. 8316582: Minor startup regression in 22-b15 due JDK-8310929 openjdk/jdk#15836 cl4es修改去掉ByteArrayLittleEndian,但性能会下降(比PR 14699差,但比之前好)。

当前的提交合并了前2个,但和第3个PR 15836的修复方法不同,使用Unsafe代替ByteArrayLittleEndian。性能没有回退,并且不会导致JVM启动变慢。

@wenshao wenshao force-pushed the optim_int_long_to_string branch from 1f32a54 to b7c133a Compare November 1, 2023 07:01
@wenshao
Copy link
Author

wenshao commented Nov 1, 2023

JDK 11没有ByteArrayLittleEndian,只能合成一个commit来提交了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants