tink-crypto / tink

Tink is a multi-language, cross-platform, open source library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.
https://developers.google.com/tink
Apache License 2.0
13.47k stars 1.18k forks source link

Improve AesGcmSiv `Aead` performance by optimizing classpath check #686

Closed ks-yim closed 1 year ago

ks-yim commented 1 year ago

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 CPU cycles consumed to encrypt and decrypt data and 12% or more throughput gain can be obtained by optimizing away the Class#forName invocation.

Modification:

Cache the result of the classpath check in AesGcmSiv

BM Results:

CPU Profiling Result:

google-cla[bot] commented 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.

morambro commented 1 year ago

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.

ks-yim commented 1 year ago

@morambro Ah, haven't noticed the change. I will move the PR to the new repo, thanks!

morambro commented 1 year ago

Thanks!

ks-yim commented 1 year ago

Closing in favor of https://github.com/tink-crypto/tink-java/pull/5