It’s not a new topic whatsoever (links at the end), so let’s just jump to benchmark results.
Performance for encoding 10K characters for different JDKs.
java.util.Base64 is a clear winner performing almost 10x faster.
Performance for different data sizes (from 1 byte to 10K bytes) for openjdk-17. As you could see in the previous chart, openjdk-8 performs worse, but still
java.util.Base64 is clearly better in all cases.
It’s clearly a time to replace old usages of Apache Commons for base64 encoding. Unless you are on JDK7 or lower, then it’s time to upgrade this part first ;-) (as
java.util.Base64 was introduced in JDK8)
- Base64 encoding and decoding performance: a big good article from 2014 with multiple libraries comparison. Site doesn’t exist anymore, so link to web archive.
- A Fast and Correct Base 64 Codec: AWS’s take on base64 (spoiler, their implementation is more “correct”).
- Follow up on Base64 Codec Performance: AWS’s performance benchmark (no source code and clear results, though).
- Java Base64 Encoding and Decoding: basic tutorial.