FasterXML / jackson-core

Core part of Jackson that defines Streaming API as well as basic shared abstractions
Apache License 2.0
2.27k stars 799 forks source link

Floating-point write performance on JDK 21: JDK now (slightly) faster than "Schubfab"-optimized path #1351

Closed cowtowncoder closed 1 month ago

cowtowncoder commented 1 month ago

Something I found out when writing:

https://cowtowncoder.medium.com/jackson-2-18-fast-vector-reads-writes-6c2cf99c4594

is that while with JDKs 8 and 17 optimized floating-point writes (with StreamWriteFeature.USE_FAST_DOUBLE_WRITER) is about 2x as fast as JDK one, with JDK 21, JDK version is now slightly faster.

Code Jackson uses is from https://github.com/c4f7fcce9cb06515/Schubfach (as per notes on 3 classes in com.fasterxml.jackson.core.io.schubfach).

So it'd be good to consider what to do, if anything:

  1. Could there be newer version of "Schubfach" code implementation to use?
  2. Is there an explanation of why/how JDK 21 (and later presumably, could try) is so much faster than earlier versions (link would be nice to add)
  3. Should we document feature, suggesting it probably should not be enabled for JDKs 21 and above)
cowtowncoder commented 1 month ago

cc @pjfanning

pjfanning commented 1 month ago

The author of the Schubfach code seems to work on the JDK these days. https://github.com/c4f7fcce9cb06515/Schubfach/blob/master/todec/src/math/DoubleToDecimal.java

Raffaello Giulietti

In the end of the day, it is good that the JDK has good performance. We can suggest that users only use StreamWriteFeature.USE_FAST_DOUBLE_WRITER=true if they are using an older JDK.

cowtowncoder commented 1 month ago

Yes, absolutely good we need not override JDK handling. As long as we can be confident implementation has caught up which seems to be the case. Good learnings!

cowtowncoder commented 1 month ago

Updated Javadocs to indicate improvements up to JDK 17, but not 21 or above; closing the issue.