kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Replace slow JDK Double parsing with Daniel Lemire's fast_float algorithm

Open stefanthaler opened this issue 1 year ago • 2 comments

What is your use-case and why do you need this feature?

I need to serialize objects with many Doubles in them. The JDK's default Double serialization is slow, particularly on Android phones.

I can use custom serializers of course, but I would rather have a fast default implementation.

Describe the solution you'd like

Use Daniel Lemire's fast_float algorithm for parsing Double instead of the JDK's default. The speedup is considerable, almost 4x on Android for my quick checks.

stefanthaler avatar May 24 '24 11:05 stefanthaler

Is it a drop-in replacement though? We can't swap one implementation for another unless it always gives the same result, and IIRC, java.lang.Double.valueOf support various input formats, such as hexadecimal.

sandwwraith avatar May 27 '24 14:05 sandwwraith

I think the most impactful thing would be to adopt it in the downstream toolchain itself instead.

The problem with changing such an intricate thing as Java's Double parser is that it might introduce quite subtle inconsistencies across the systems; also, for the sake of some (yet to be defined) performance gain, we'll have to (potentially significantly) compromise binary size and, potentially, some other performance characteristics

qwwdfsad avatar May 27 '24 14:05 qwwdfsad

Efforts required to implement the algorithm in kotlinx.serialization are pretty much the same as implementing it in the Kotlin stdlib (https://youtrack.jetbrains.com/issue/KT-75355). However, unlikely we will be able to do that right now (see YT issue for details).

fzhinkin avatar Feb 20 '25 18:02 fzhinkin