You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at UTF8StreamJsonParser#finishString which seems to mostly consist of scanning for a trailing quote, with an optimized code path for ASCII strings. This optimized code path for ASCII strings could be further optimized by using VarHandles to compare multiple bytes at once.
privatestaticfinalVarHandleVH_LE_LONG =
MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.LITTLE_ENDIAN);
[...]
while (ptr <= max - Long.BYTES) {
longnext8Bytes = VH_LE_LONG.get(inputBuffer, ptr);
if ((next8Bytes & 0x8080808080808080L) != 0) {
// At least one of the bytes has the higher bit set, this is not a pure ASCII stringbreak;
}
if (hasValue(next8Bytes, INT_QUOTE)) { // Implement hasValue based on https://graphics.stanford.edu/~seander/bithacks.html#ValueInWord// one of the next 8 bytes is a quotebreak;
}
// Maybe this loop can become unnecessary via https://github.com/FasterXML/jackson-core/issues/910for (inti = 0; i < Long.BYTES; ++i) {
outBuf[outPtr + i] = (char) inputBuffer[ptr + i];
}
ptr += Long.BYTES;
outPtr += Long.BYTES;
}
while (ptr < max) {
intc = (int) inputBuffer[ptr] & 0xFF;
if (codes[c] != 0) {
if (c == INT_QUOTE) {
_inputPtr = ptr+1;
_textBuffer.setCurrentLength(outPtr);
return;
}
break;
}
++ptr;
outBuf[outPtr++] = (char) c;
}
As VarHandles were introduced in Java 9, this would require releasing a MR JAR or bumping the min required version.
I haven't had a chance to measure if it made a significant difference but wanted to log the idea in case it gets someone's attention.
The text was updated successfully, but these errors were encountered:
Sounds interesting, although I would not be too excited about multi-release jars (I know there's bit of that already for FastDoubleParser, but that's just merged in and not maintained as part of jackson-core).
When (... if) we finally get back to Jackson 3.0 work tho, baseline is probably going to be increased past Java 8 (at least 11 but I suspect by the time, 17 would be better choice) and that'd be be moot issue.
But as per @pjfanning's comments, what would really be interesting would be jmh benchmarking.
I was looking at
UTF8StreamJsonParser#finishString
which seems to mostly consist of scanning for a trailing quote, with an optimized code path for ASCII strings. This optimized code path for ASCII strings could be further optimized by using VarHandles to compare multiple bytes at once.The current code looks like this:
and could become something like:
As VarHandles were introduced in Java 9, this would require releasing a MR JAR or bumping the min required version.
I haven't had a chance to measure if it made a significant difference but wanted to log the idea in case it gets someone's attention.
The text was updated successfully, but these errors were encountered: