⚡️ Speed up method Crypto.encodeBase64 by 49%#90
Open
codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
Open
⚡️ Speed up method Crypto.encodeBase64 by 49%#90codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
Crypto.encodeBase64 by 49%#90codeflash-ai[bot] wants to merge 1 commit intofix/add-mockito-test-dependencyfrom
Conversation
The change replaces the gnu.crypto Base64 call with java.util.Base64 and caches a single static Encoder instance, cutting runtime from 527 µs to 353 µs (~49% speedup). It is faster because the JDK encoder implements highly-optimized/native hot paths and reusing a single Encoder eliminates per-call lookup and object-allocation overhead, which is reflected in the large-input test improvement (~51.8% faster). Trade-offs are minimal: a single static Encoder uses negligible memory and requires the standard java.util.Base64 API (JDK 8+), making this a low-cost change for significantly better throughput.
misrasaurabh1
approved these changes
Mar 4, 2026
misrasaurabh1
left a comment
There was a problem hiding this comment.
this seems to be good for larger characters, but stability needs to be tested for smaller characters where i see perf regressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📄 49% (0.49x) speedup for
Crypto.encodeBase64inclient/src/com/aerospike/client/util/Crypto.java⏱️ Runtime :
527 microseconds→353 microseconds(best of169runs)📝 Explanation and details
The change replaces the gnu.crypto Base64 call with java.util.Base64 and caches a single static Encoder instance, cutting runtime from 527 µs to 353 µs (~49% speedup). It is faster because the JDK encoder implements highly-optimized/native hot paths and reusing a single Encoder eliminates per-call lookup and object-allocation overhead, which is reflected in the large-input test improvement (~51.8% faster). Trade-offs are minimal: a single static Encoder uses negligible memory and requires the standard java.util.Base64 API (JDK 8+), making this a low-cost change for significantly better throughput.
✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-Crypto.encodeBase64-mmbh28udand push.