Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it really faster than Codecutils?? #2955

Open
tmdgusya opened this issue Mar 30, 2023 · 3 comments
Open

Is it really faster than Codecutils?? #2955

tmdgusya opened this issue Mar 30, 2023 · 3 comments
Assignees
Labels
bug This issue is a bug. p3 This is a minor priority issue

Comments

@tmdgusya
Copy link

tmdgusya commented Mar 30, 2023

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. I tested which is the faster one between CodecUtils and DataTypeConverter. As described comment on function, DataTypeConverter should be faster than CodecUtils. 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 tmdgusya added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 30, 2023
@debora-ito
Copy link
Member

@tmdgusya what is the ask here?

@debora-ito debora-ito added response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. and removed needs-triage This issue or PR still needs to be triaged. labels Mar 30, 2023
@debora-ito debora-ito self-assigned this Mar 30, 2023
@tmdgusya
Copy link
Author

tmdgusya commented Mar 30, 2023

@debora-ito
image

            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.

@github-actions github-actions bot removed the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label Mar 31, 2023
@debora-ito debora-ito added the p3 This is a minor priority issue label Apr 1, 2023
@YanivKunda
Copy link

@tmdgusya did you check that in a multi-threaded environment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

3 participants