RFR: 8378698: Optimize Base64.Encoder#encodeToString [v2]

Chen Liang liach at openjdk.org
Thu Feb 26 23:18:01 UTC 2026


On Thu, 26 Feb 2026 20:28:12 GMT, Patrick Strawderman <duke at openjdk.org> wrote:

>> Avoid a byte array copy in encodeToString by using JavaLangAccess#uncheckedNewStringWithLatin1Bytes
>
> Patrick Strawderman has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add JMH benchmark for encodeToString

My results with this benchmark (yes, took me two of 33:25 to run!)

Without patch:

Benchmark                                (inputSize)   Mode  Cnt      Score     Error   Units
Base64EncodeToString.testEncodeToString           10  thrpt   25  60318.739 ± 912.624  ops/ms
Base64EncodeToString.testEncodeToString          100  thrpt   25  34639.846 ± 564.989  ops/ms
Base64EncodeToString.testEncodeToString         1000  thrpt   25   4760.465 ±  66.707  ops/ms
Base64EncodeToString.testEncodeToString        10000  thrpt   25    416.867 ±   6.590  ops/ms


With patch:

Benchmark                                (inputSize)   Mode  Cnt      Score      Error   Units
Base64EncodeToString.testEncodeToString           10  thrpt   25  73585.221 ± 1250.220  ops/ms
Base64EncodeToString.testEncodeToString          100  thrpt   25  37766.561 ±  991.396  ops/ms
Base64EncodeToString.testEncodeToString         1000  thrpt   25   8198.071 ±  193.539  ops/ms
Base64EncodeToString.testEncodeToString        10000  thrpt   25    725.249 ±   11.494  ops/ms

-------------

PR Comment: https://git.openjdk.org/jdk/pull/29920#issuecomment-3969795570


More information about the core-libs-dev mailing list