Closed ks-yim closed 1 year ago
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.
Hi @ks-yim, could you please open this PR in https://github.com/tink-crypto/tink-java?
We are splitting and moving our repos to https://github.com/tink-crypto.
@morambro Ah, haven't noticed the change. I will move the PR to the new repo, thanks!
Thanks!
Closing in favor of https://github.com/tink-crypto/tink-java/pull/5
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 CPU cycles consumed to encrypt and decrypt data and 12% or more throughput gain can be obtained by optimizing away theClass#forName
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 Silicon.Before
After
CPU Profiling Result:
Before
Encryption![flame-graph-cpu](https://user-images.githubusercontent.com/35995647/222684677-b31213e1-b876-4228-a609-2c9015ac88e5.svg)
Decryption![flame-graph-cpu](https://user-images.githubusercontent.com/35995647/222685025-681fed16-480e-412c-83ec-74c9294e8874.svg)
After
Encryption![flame-graph-cpu](https://user-images.githubusercontent.com/35995647/222685439-cb92ccee-9c2f-4cc8-bda0-86bfcd95bf6c.svg)
Decryption![flame-graph-cpu](https://user-images.githubusercontent.com/35995647/222685359-6be89698-1514-4509-890b-38799bf6bf62.svg)