-
Notifications
You must be signed in to change notification settings - Fork 16
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
Improve AesGcmSiv Aead performance by optimizing classpath check #5
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Motivation: `Aead` implementation for `AesGcmSiv` checks if `GCMParameterSpec` class exists in classpath by invoking `Class#forName` method whenever data gets encrypted or decrypted. A benchmark on `AesGcmSiv` claims that `Class#forName` accounts for 4-5% of the total CPU cycles consumed for data en/decryption and 12% or more throughput gain can be obtained by optimizing away the `Class#forName` method invocation. Modification: Cache the result of the classpath check in `AesGcmSiv`
@@ -58,6 +58,18 @@ protected Cipher initialValue() { | |||
private static final int IV_SIZE_IN_BYTES = 12; | |||
private static final int TAG_SIZE_IN_BYTES = 16; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is slightly easier to understand if you just do:
private static final boolean HAS_GCM_PARAMETER_SPEC_CLASS = checkForGCMParameterSpec();
private static final boolean checkForGCMParameterSpec() {
try {
Class.forName("javax.crypto.spec.GCMParameterSpec");
} catch (ClassNotFoundException e) {
return false;
}
return true;
}
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response.
No objection to it. I will send a new commit!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it, PTAL 🙏.
Thank you. I will try to merge this but still have to see if I figure out how we set this up. Please ping me if it didn't work. |
@tholenst Thanks for reviewing this, but I didn't get you in the last sentence. |
Sorry for being unclear. I am working on merging this, but the process works in some predefined way interacting with the Google-internal repository. I do not have experience with the process, so it might happen that it doesn't work and I forget about it. It should be merged on Monday, if it didn't work I made a mistake and I would welcome a reminder. |
Hmm, it seems this was now merged, but it was not associated with this PR, see f7ba536 Nevertheless, it seems it's correctly associated with you -- at least the commit seems to show up on your stats. I guess like this it's no big deal? WDYT? |
@tholenst thanks for working on this, I will close the PR, then. |
Motivation:
Aead
implementation forAesGcmSiv
checks ifGCMParameterSpec
class exists in classpath by invokingClass#forName
method whenever data gets encrypted or decrypted.A benchmark on
AesGcmSiv
claims thatClass#forName
accounts for 4-5% of the total CPU cycles consumed for data en/decryption and 12% or more throughput gain can be obtained by optimizing away theClass#forName
method invocation.Modification:
Cache the result of the classpath check in
AesGcmSiv
BM Results:
BM Code
Run on:
Conscrypt
custom build based on 3051cda to utilize AES-NI on Apple SiliconBefore
After
CPU Profiling Result:
Encryption
Before
After
Decryption
Before
After