Is it really faster than Codecutils??
Describe the bug
https://github.com/aws/aws-sdk-java/blob/8542b3ddc6be843dc910b3ccb1e6aeb3cc05c001/aws-java-sdk-core/src/main/java/com/amazonaws/util/Base64.java
In Base64 files, you described that if you don't use JAXB, then will fallback to SDK implementation which may be less performant. So, I tested this. That mean I tested which is the fast CodecUtils and DataTypeConverter. But, DataTypeConverter always slower than CodecUtils.
Expected Behavior
DataTypeCoverter is better than CodecUtils. (But Always lose)
Current Behavior
DataTypeCoverter is always slower than CodecUtils.
Reproduction Steps
class LearningTest : FunSpec({
test("which is faster?") {
val codec = Base64Codec()
// initialize Base64 Class because we have to execute static block code before testing
Class.forName("com.amazonaws.util.Base64")
Class.forName("javax.xml.bind.DatatypeConverter");
// 1. DatatypeConverter
val usingDatatypeConverter = measureNanoTime {
DatatypeConverter.printBase64Binary(byteArrayOf(
-86,
24,
85,
104,
67,
51,
80,
-80,
-68,
-48,
-35,
28,
1,
-92,
-43,
110
))
}
val hello = measureNanoTime { println("Hello") }
// 2. CodecUtils.toStringDirect
val usingCodeUtils = measureNanoTime {
CodecUtils.toStringDirect(
codec.encode(
byteArrayOf(
-86,
24,
85,
104,
67,
51,
80,
-80,
-68,
-48,
-35,
28,
1,
-92,
-43,
110
)
)
)
}
println("usingDatatypeConverter: $usingDatatypeConverter") // 6455000
println("usingCodeUtils: $usingCodeUtils") // 386000
println("hello: $hello") // 30417
// usingBase64 is faster than usingCodeUtils (fail)
usingCodeUtils.shouldBeGreaterThan(usingDatatypeConverter)
}
})
Possible Solution
No response
Additional Information/Context
implementation("com.amazonaws:aws-java-sdk-s3:1.12.174")
implementation("javax.xml.bind:jaxb-api:2.3.1")
implementation("com.amazonaws:aws-java-sdk-s3")
AWS Java SDK version used
1.12.174
JDK version used
17
Operating System and version
macOS monterey 12.6 (21G115) M1Max Memory: 32GB
@tmdgusya what is the ask here?
@debora-ito

LOG.warn("JAXB is unavailable. Will fallback to SDK implementation which may be less performant." +
"If you are using Java 9+, you will need to include javax.xml.bind:jaxb-api as a dependency.");
public static String encodeAsString(byte... bytes) {
if (bytes == null) {
return null;
}
if (isJaxbAvailable) {
try {
return DatatypeConverter.printBase64Binary(bytes);
} catch (NullPointerException ex) {
// https://netbeans.org/bugzilla/show_bug.cgi?id=224923
// https://issues.apache.org/jira/browse/CAMEL-4893
// Note the converter should eventually be initialized and printBase64Binary should start working again
LOG.debug("Recovering from JAXB bug: https://netbeans.org/bugzilla/show_bug.cgi?id=224923", ex);
}
}
return bytes.length == 0 ? "" : CodecUtils.toStringDirect(codec.encode(bytes));
}
High performant(DataTypeConverter) Less performant(CodecUtils)
According to the comment in this file, DataTypeConverter should be faster than CodecUtils. However, when I tested it, CodecUtils was always faster than DataTypeConverter.
@tmdgusya did you check that in a multi-threaded environment?
@tmdgusya did you check that in a multi-threaded environment?
No, I didn't
@tmdgusya apologies for the lack of updates in this issue. Unfortunately we won't have the chance to do a deep dive before going into Maintenance Mode, so I'll go ahead and close this.
This issue is now closed.
Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.