Skip to content
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

Add a boolean to OpenSSLAeadCipher to control optimisations. #871

Merged
merged 1 commit into from Aug 13, 2020

Conversation

prbprbprb
Copy link
Collaborator

Controls whether the no-copy optimisations for direct ByteBuffers
are enabled. If false, then the inherited default behaciour from
CipherSpi is used.

Controls whether the no-copy optimisations for direct ByteBuffers
are enabled. If false, then the inherited default behaciour from
CipherSpi is used.
@prbprbprb prbprbprb requested a review from daulet August 13, 2020 11:21
@prbprbprb prbprbprb merged commit 785ead0 into google:master Aug 13, 2020
@prbprbprb prbprbprb deleted the bytebuf_switch branch August 13, 2020 14:01
@@ -223,6 +228,9 @@ boolean allowsNonceReuse() {
@Override
protected int engineDoFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferException,
IllegalBlockSizeException, BadPaddingException {
if (!ENABLE_BYTEBUFFER_OPTIMIZATIONS) {
return super.engineDoFinal(input, output);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the peanut gallery:

Instead of expensive ByteBuffer.allocateDirect calls, could this method leverage the BufferAllocator? Static state isn't ideal, but using ConscryptEngine.getDefaultBufferAllocator() could reduce overhead. Otherwise, should super.engineDoFinal be used if either buffer is non-direct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Absolutely we should reduce overhead further, but this is a starting point and I must admit we only really benchmarked the gRPC case where the buffers are always direct, and where it significantly improves performance.

I'm not sure which would be slower, allocateDirect() and copy or super.engineDoFinal() with its loops of byte array copying and possibly the answer is platform-specific. I guess the code would be simpler at least if we punted everything apart from the happy path to super.

Using BufferAllocator I think would definitely improve things and that's probably the next step, followed by handling the doUpdate() case and possibly other ciphers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants