RFR: 8367324: Avoid redundant parsing when formatting with DigitList

Raffaello Giulietti rgiulietti at openjdk.org
Wed Sep 10 14:03:50 UTC 2025


On Fri, 5 Sep 2025 14:37:01 GMT, Johannes Graham <duke at openjdk.org> wrote:

>> When formatting doubles or BigDecimals, DigitList first formats them as a string and then parses the resultant string to extract the mantissa and the exponent. This can be done more directly. This allows removing some parsing code and removes a cached byte array.
>> 
>> This also facilitates potential cleanups in FloatingDecimal (removal of getChars method) but I've left that for later to minimize conflicts with other changes there.
>
> @rgiulietti This requires the use of the `getDigits` and `getDecimalExponent` methods in `FloatingDecimal`, which are proposed to be removed in https://github.com/openjdk/jdk/pull/26990

@j3graham Yes, they are proposed to be removed since they are currently useless.
Would you like me to reconsider their removals in my [draft PR](https://github.com/openjdk/jdk/pull/26990)?

> Benchmark results Aarch64 M4
> 
> 
> Benchmark                                              Mode  Cnt      Score     Error   Units
> -DefFormatterBench.testDefNumberFormatter             thrpt   15  15612.853 ± 448.025  ops/ms
> -DefFormatterBench.testLargeBigDecDefNumberFormatter  thrpt   15   4075.254 ±  58.170  ops/ms
> -DefFormatterBench.testSmallBigDecDefNumberFormatter  thrpt   15  12467.137 ± 194.961  ops/ms
> +DefFormatterBench.testDefNumberFormatter             thrpt   15  19196.464 ± 475.871  ops/ms  +26%
> +DefFormatterBench.testLargeBigDecDefNumberFormatter  thrpt   15   4981.756 ±  82.088  ops/ms  +22%
> +DefFormatterBench.testSmallBigDecDefNumberFormatter  thrpt   15  15936.774 ± 108.450  ops/ms  +28%
> Finished running test 'micro:DefFormatterBench'
> 
> 
> This includes adding a fast-path in BigInteger.toString to help extract significant digits from a BigDecimal without a slowdown.

@j3graham [JDK-8367324](https://bugs.openjdk.org/browse/JDK-8367324)

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

PR Comment: https://git.openjdk.org/jdk/pull/27118#issuecomment-3258648900
PR Comment: https://git.openjdk.org/jdk/pull/27118#issuecomment-3274449176


More information about the core-libs-dev mailing list