Conversation
7d395b3 to
34c3829
Compare
|
@plokhotnyuk feel free to ignore this but if you time, it would be nice to get your input on the XJBWriter. I added support for writing to char arrays as well as byte arrays because this is useful in some Jackson code paths. The char stream code may not be as heavily optimised as the byte stream path. |
Great work! Have you used AI agents or translated it manually to Java? The next step could be using James Anhalt's algorithm for faster writing of mantissas: https://jk-jeon.github.io/posts/2022/02/jeaiii-algorithm/ Or you can leverage 3 digit LUT table to reduce cycles as it is done for integer numbers. |
|
@plokhotnyuk mainly AI agent work but it was pretty iterative so possibly not a great time saver in this case. |
|
@cowtowncoder if this does get merged in time for 3.3.0, the CSV module could also benefit by uptaking the new NumberOutput APIs that this PR adds. |
|
@pjfanning Hoping to get to this next. |
|
Hmmmh. I have some concerns based on Claude-assisted code review. First is LICENSE: which may be easy to address. Will add other notes too, but first things first. |
|
Second: does XJB require use of VarHandles? If not, maybe first version could just use added HOWEVER, also: Claude claims: |
|
@cowtowncoder AnimalSniffer failures are what sent me down the route of using indirection for the VarHandles. The docs that I found suggest that Android should support VarHandles at the version we support but AnimalSniffer doesn't appear to agree. |
@cowtowncoder I updated the licenses in META-INF - c729911 |
|
@cowtowncoder I'd prefer to keep the VarHandles as they really help the performance. For instance, we make use of them in the binary dataformats now. |
|
@pjfanning Ok. Yes, I know about binary (and some textual?) backends wrt recent PRs. One last concern code review mentioned: some of serializations change for numbers -- not in wrong way (they still round-trip), but differ from what JDK produces. This may be fine, just wanted to mention; at least it can trigger test failures downstream. |
|
@cowtowncoder The writer is opt-in but I understand the worry about the different output for some numbers. @plokhotnyuk what do you think about the issue described in #1656 (comment) ? |
Originally XJB formats without dot when mantissa is just one digit (for instance 1e-45 - the shortest representation). But for Java there is a formatting rule that dot and at least one digit after are required, so that why 1.0E-45 reappears like on 17 JDK. |
|
@pjfanning Yes, opt-in is probably sufficient to allow change. |
- Add char[] overloads to XJBWriter (writeFloat, writeDouble) - Add MAX_FLOAT_CHARS and MAX_DOUBLE_CHARS constants to NumberOutput - Add outputFloat and outputDouble char[] methods to NumberOutput - Update WriterBasedJsonGenerator to use char[] fast path - Add NumberOutputFloatDoubleTest and XJBWriterCharTest test files
XJBWriter throws ArithmeticException for non-finite values. When WRITE_NAN_AS_STRINGS is disabled, NaN/Infinity must still be written as raw strings (not quoted). Check Double.isFinite/Float.isFinite before calling the fast path, falling back to toString() for non-finite values.
- Add non-finite checks using bits already available (e2IEEE == 0xFF/0x7FF) - NaN writes 'NaN', Infinity writes 'Infinity'/'-Infinity' to buffer - Remove Double.isFinite/Float.isFinite checks from generators - Remove now-unused illegalNumberError methods - Update tests to expect correct output instead of ArithmeticException
writeFloat/writeDouble now handle NaN/Infinity directly, so toString no longer needs its own checks.
write3Digits used a 4-byte setInt store for the exponent, the last write of the longest output (-2.2250738585072014E-308, 24 chars), so it touched 25 bytes. UTF8JsonGenerator reserves exactly MAX_DOUBLE_BYTES, giving an AIOOBE when the value landed 24 bytes from the end of the output buffer. Write exactly 3 bytes instead. Also size the toString() scratch buffers from MAX_*_BYTES rather than MAX_*_CHARS, and refresh the NumberOutput javadoc: non-finite values are handled now, and the notFinite links / param types on the output* overloads were wrong. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qqdq57uPQx3jxcg3WsoUiq
…s (24/15) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qqdq57uPQx3jxcg3WsoUiq
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qqdq57uPQx3jxcg3WsoUiq
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ssors Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.